摘要: 这个题之前做过,实在没想出什么好方法,今天突然发现这个完全就是个有环链表找开始进入环的题目,真是相当精巧public class Solution { public int findDuplicate(int[] nums) { int slow = 0; int ... 阅读全文
posted @ 2015-12-05 14:31 Weizheng_Love_Coding 阅读(119) 评论(0) 推荐(0)
摘要: class MyStack { // Push element x onto stack. Queue queue = new LinkedList(); public void push(int x) { Queue q = new LinkedList(); ... 阅读全文
posted @ 2015-12-05 13:34 Weizheng_Love_Coding 阅读(124) 评论(0) 推荐(0)
摘要: public class Solution { public TreeNode invertTree(TreeNode root) { if (root == null) { return root; } TreeNode tmp... 阅读全文
posted @ 2015-12-05 13:29 Weizheng_Love_Coding 阅读(88) 评论(0) 推荐(0)
摘要: public class Solution { public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int area = (C - A) * (D - B) + (G -... 阅读全文
posted @ 2015-12-05 13:25 Weizheng_Love_Coding 阅读(91) 评论(0) 推荐(0)
摘要: public class Solution { public TreeNode buildTree(int[] inorder, int[] postorder) { return helper(inorder, postorder, 0, inorder.length - 1,... 阅读全文
posted @ 2015-12-05 09:49 Weizheng_Love_Coding 阅读(155) 评论(0) 推荐(0)
摘要: public class Solution { public String largestNumber(int[] nums) { int length = nums.length; Queue queue = new PriorityQueue(length, n... 阅读全文
posted @ 2015-12-05 09:19 Weizheng_Love_Coding 阅读(109) 评论(0) 推荐(0)
摘要: 主要是一下步骤1.delete space in front of str2.check if str startsWith other characters3.check if str is positive4.check the end of str5.check if overflowpubl... 阅读全文
posted @ 2015-12-05 08:39 Weizheng_Love_Coding 阅读(142) 评论(0) 推荐(0)
摘要: 第一个是普通二叉树,第二个是bstpublic class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if (root == null) { ... 阅读全文
posted @ 2015-12-05 08:00 Weizheng_Love_Coding 阅读(130) 评论(0) 推荐(0)
摘要: public class Solution { public int[][] generateMatrix(int n) { int level = (n + 1) / 2; int[][] result = new int[n][n]; int tm... 阅读全文
posted @ 2015-12-05 06:44 Weizheng_Love_Coding 阅读(139) 评论(0) 推荐(0)
摘要: 上面是lc的单链表题目,下面我又自己加了个双向链表的情况public class Solution { public ListNode swapPairs(ListNode head) { if (head == null || head.next == null) { ... 阅读全文
posted @ 2015-12-05 03:54 Weizheng_Love_Coding 阅读(158) 评论(0) 推荐(0)
摘要: 在无重复元素时,中间元素与首元素相等,表示一共只有两个元素,low与high各指向一个。由于while循环中限制的大小关系,因此返回nums[high]即为最小值。然而当存在重复元素时,该条件并不能表示一共只有low和high指向的两个元素,而是说明low指向的元素重复了,因此删除其一,low ++... 阅读全文
posted @ 2015-12-05 03:16 Weizheng_Love_Coding 阅读(131) 评论(0) 推荐(0)
摘要: public class Solution { public int[] productExceptSelf(int[] nums) { int length = nums.length; int[] result = new int[length]; ... 阅读全文
posted @ 2015-12-05 02:28 Weizheng_Love_Coding 阅读(124) 评论(0) 推荐(0)