上一页 1 ··· 8 9 10 11 12 13 14 15 下一页
摘要: //注意,1,要判断null;2,要注意ArrayList直接复制会被一起改变。要通过new的方式来操作。public class Solution { public static void main(String[] args){ TreeNode root = new Tre... 阅读全文
posted @ 2015-12-28 11:53 仔细思考一切 阅读(193) 评论(0) 推荐(0)
摘要: import java.util.*; public class LCA { public static int getLCA(int a, int b){ if(a b){ a = a/2; ... 阅读全文
posted @ 2015-12-28 09:17 仔细思考一切 阅读(169) 评论(0) 推荐(0)
摘要: 注意:就算斜率相等,但是,如果截距也相等,那么是属于相交,所以要特殊判断。public class CrossLine { public boolean checkCrossLine(double s1, double s2, double y1, double y2) { // ... 阅读全文
posted @ 2015-12-25 09:27 仔细思考一切 阅读(148) 评论(0) 推荐(0)
摘要: public class Ants { public double antsCollision(int n) { // write code here return (1 - Math.pow(0.5,n-1)); }} 阅读全文
posted @ 2015-12-25 09:13 仔细思考一切 阅读(212) 评论(0) 推荐(0)
摘要: 这道题要利用101010来&。如下答案:public class Exchange { public int exchangeOddEven(int x) { // write code here int res =(((x & 0x55555555)>1)); ... 阅读全文
posted @ 2015-12-24 22:18 仔细思考一切 阅读(190) 评论(0) 推荐(0)
摘要: 自己的: public static int calcCost(int A,int B){ int ans = 1; int temp = A ^ B; while(temp != 1){ if(temp % 2 == 1) an... 阅读全文
posted @ 2015-12-24 17:23 仔细思考一切 阅读(164) 评论(0) 推荐(0)
摘要: public static String printBin(double num) { StringBuffer str = new StringBuffer(); str.append('0'); str.appe... 阅读全文
posted @ 2015-12-24 16:06 仔细思考一切 阅读(232) 评论(0) 推荐(0)
摘要: public class Solution { public static int binInsert(int n, int m, int i, int j) { // write code here// return n | (m << i); in... 阅读全文
posted @ 2015-12-24 12:46 仔细思考一切 阅读(338) 评论(0) 推荐(0)
摘要: 因为,没有重复值,所以只需要做一个标记就OK了。public class Successor { static boolean flag = false; static int result = 0; public int findSucc(TreeNode root, int... 阅读全文
posted @ 2015-12-22 22:21 仔细思考一切 阅读(192) 评论(0) 推荐(0)
摘要: public boolean checkBST(TreeNode root) { return isBST(root, Long.MIN_VALUE, Long.MAX_VALUE); } public boolean isBST(TreeNode root, lo... 阅读全文
posted @ 2015-12-22 20:46 仔细思考一切 阅读(203) 评论(0) 推荐(0)
上一页 1 ··· 8 9 10 11 12 13 14 15 下一页