摘要: 第一个是递归的方法,但是空间复杂度不是线性的public class Solution { public boolean verifyPreorder(int[] preorder) { return helper(preorder, 0, preorder.length - 1... 阅读全文
posted @ 2015-11-29 14:35 Weizheng_Love_Coding 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 第一个是BFSpublic class Solution { public List rightSideView(TreeNode root) { List result = new ArrayList(); if (root == null) { ... 阅读全文
posted @ 2015-11-29 13:33 Weizheng_Love_Coding 阅读(136) 评论(0) 推荐(0) 编辑
摘要: public class Solution { int result = 0; public int countUnivalSubtrees(TreeNode root) { helper(root); return result; } publi... 阅读全文
posted @ 2015-11-29 12:50 Weizheng_Love_Coding 阅读(128) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public List> groupStrings(String[] strings) { HashMap> map = new HashMap>(); for (String str :strings) { ... 阅读全文
posted @ 2015-11-29 11:16 Weizheng_Love_Coding 阅读(157) 评论(0) 推荐(0) 编辑
摘要: public class Solution { List result = new ArrayList(); public List binaryTreePaths(TreeNode root) { if (root == null) { return... 阅读全文
posted @ 2015-11-29 10:05 Weizheng_Love_Coding 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 反转后一半,然后判断,不过这样子会改变输入的数据,感觉不太好。也可以用一个栈,但是那样的话空间复杂度就不符合标准了。/** * Definition for singly-linked list. * public class ListNode { * int val; * List... 阅读全文
posted @ 2015-11-29 09:58 Weizheng_Love_Coding 阅读(98) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public String getHint(String secret, String guess) { int[] s = new int[10]; int[] g = new int[10]; int... 阅读全文
posted @ 2015-11-29 09:06 Weizheng_Love_Coding 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 一个最大堆一个最小堆 O(1)存取class MedianFinder { Queue min = new PriorityQueue(); Queue max = new PriorityQueue(10, new Comparator(){ public int comp... 阅读全文
posted @ 2015-11-29 07:43 Weizheng_Love_Coding 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 第一次一次过的hard题目,其实觉得难度应该算是中等难题。就是先找纵方向的中点,再找横方向的中点,思路类似一维的情况public class Solution { public int minTotalDistance(int[][] grid) { int row = grid... 阅读全文
posted @ 2015-11-29 07:15 Weizheng_Love_Coding 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 二分搜索public class Solution { public int hIndex(int[] citations) { int length = citations.length; if (length == 0) { return ... 阅读全文
posted @ 2015-11-29 06:56 Weizheng_Love_Coding 阅读(120) 评论(0) 推荐(0) 编辑