上一页 1 2 3 4 5 6 7 8 ··· 13 下一页
摘要: 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 阅读(133) 评论(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 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 在无重复元素时,中间元素与首元素相等,表示一共只有两个元素,low与high各指向一个。由于while循环中限制的大小关系,因此返回nums[high]即为最小值。然而当存在重复元素时,该条件并不能表示一共只有low和high指向的两个元素,而是说明low指向的元素重复了,因此删除其一,low ++... 阅读全文
posted @ 2015-12-05 03:16 Weizheng_Love_Coding 阅读(124) 评论(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 阅读(119) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int row = obstacleGrid.length; if (row == 0) { ... 阅读全文
posted @ 2015-12-04 16:42 Weizheng_Love_Coding 阅读(144) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public void rotate(int[][] matrix) { int n = matrix.length; int count = (n + 1) / 2; for (int i = 0; i... 阅读全文
posted @ 2015-12-04 14:30 Weizheng_Love_Coding 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 判断四个数是否可能通过加减乘得到二十四, 可以使用括号,思路极其像Expression Add Operators, 区别是在处理乘号的时候,一种是没有括号的,和Expression Add Operators一样,一种是带有括号的,其实就是把乘号当作加号来计算public class Soluti... 阅读全文
posted @ 2015-12-04 12:45 Weizheng_Love_Coding 阅读(174) 评论(0) 推荐(0) 编辑
摘要: dp的方法比较简单就不写了。这里用分治法,对与一个数组,最大的子区间可以在left 到 mid这一段, 也可能划过mid, 也可能在mid 到 right, 所以分别求这三段,取最大的结果。求左右段最大的时候才用分治的想法。算法复杂度为o(nlogn)public class Solution { ... 阅读全文
posted @ 2015-12-04 11:53 Weizheng_Love_Coding 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 两种解法,第一个是利用了前序遍历递增的特点public class Solution { long count = Long.MIN_VALUE; public boolean isValidBST(TreeNode root) { if (root == null) { ... 阅读全文
posted @ 2015-12-04 09:42 Weizheng_Love_Coding 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 1 public class Solution { 2 public List> zigzagLevelOrder(TreeNode root) { 3 List> result = new ArrayList>(); 4 if (root == null)... 阅读全文
posted @ 2015-12-04 09:25 Weizheng_Love_Coding 阅读(113) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 13 下一页