10 2018 档案
摘要:1 class Solution { 2 public String reorganizeString(String S) { 3 if(S.length() == 0) return ""; 4 int[] arr = new int[26]; 5 int max = 0; 6 for(int i = 0; i...
阅读全文
posted @ 2018-10-31 12:52
jasoncool1
摘要:https://leetcode.com/problems/flatten-nested-list-iterator/discuss/80147/Simple-Java-solution-using-a-stack-with-explanation
阅读全文
posted @ 2018-10-31 12:13
jasoncool1
摘要:https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/discuss/87739/Java-Strict-O(N)-Two-Pointer-Solution window分别为1-26
阅读全文
posted @ 2018-10-31 11:32
jasoncool1
摘要:1 //dfs 2 class Solution { 3 public boolean checkValidString(String s) { 4 if(s.length() == 0) return true; 5 return dfs(s, 0, 0); 6 7 } 8 9 public ...
阅读全文
posted @ 2018-10-31 04:15
jasoncool1
摘要:https://leetcode.com/problems/number-of-longest-increasing-subsequence/discuss/107293/JavaC++-Simple-dp-solution-with-explanation 每次记载最大长度 然后最后遍历 把等于最
阅读全文
posted @ 2018-10-30 10:15
jasoncool1
摘要:1 class Solution { 2 int[] colors; 3 public boolean possibleBipartition(int N, int[][] dislikes) { 4 if(dislikes.length == 0) return true; 5 HashMap> graph = new HashMap(...
阅读全文
posted @ 2018-10-30 05:12
jasoncool1
摘要:Serialize 用BFS 中间空格分开Deserialize 用一个queue存起来new的TreeNode 下次调用它进行构造
阅读全文
posted @ 2018-10-29 12:21
jasoncool1
摘要:1 class Solution { 2 public boolean backspaceCompare(String S, String T) { 3 if(S.length() == 0 || T.length() == 0){ 4 return S.equals(T); 5 } 6 StringBu...
阅读全文
posted @ 2018-10-29 10:23
jasoncool1
摘要:1 class Solution { 2 public boolean validUtf8(int[] data) { 3 if(data.length == 0) return false; 4 int start = 0; 5 while(start = data.length || helper(data[start+1])...
阅读全文
posted @ 2018-10-29 09:24
jasoncool1
摘要:很像图的问题 实际上只用考虑indegree 当indegree等于0的时候 就可以被放进queue 进行bfs 最后能放进n个course就可以返回
阅读全文
posted @ 2018-10-29 06:44
jasoncool1
摘要:https://leetcode.com/problems/evaluate-division/discuss/88169/Java-AC-Solution-using-graph 建立graph dfsvalue是按照值建立的 这样dfs的时候可以直接乘
阅读全文
posted @ 2018-10-28 12:27
jasoncool1
摘要:https://leetcode.com/problems/find-peak-element/discuss/50232/Find-the-maximum-by-binary-search-(recursion-and-iteration)
阅读全文
posted @ 2018-10-28 11:06
jasoncool1
摘要:1 class Solution { 2 public List topKFrequent(String[] words, int k) { 3 HashMap map = new HashMap(); 4 List res = new ArrayList(); 5 if(words.length == 0) return res...
阅读全文
posted @ 2018-10-28 10:27
jasoncool1
摘要:1 class Trie { 2 class TrieNode{ 3 char label; 4 boolean flag; 5 TrieNode[] children; 6 TrieNode(char c){ 7 label = c; 8 flag = fal...
阅读全文
posted @ 2018-10-28 06:19
jasoncool1
摘要:1 class Solution { 2 Random random = new Random(); 3 int[] arr; 4 5 public Solution(int[] nums) { 6 arr = nums; 7 } 8 9 public int pick(int target) { 10 ...
阅读全文
posted @ 2018-10-28 05:36
jasoncool1
摘要:这道题要用Set去做因为没有sort过 所以在后面也可能出现重复的东西 https://leetcode.com/problems/increasing-subsequences/discuss/97130/Java-20-lines-backtracking-solution-using-set-
阅读全文
posted @ 2018-10-28 04:27
jasoncool1
摘要:1 class Solution { 2 public double knightProbability(int N, int K, int r, int c) { 3 if(K == 0) return 1; 4 double[][][] dp = new double[K+1][N][N]; 5 int[][] move = ...
阅读全文
posted @ 2018-10-28 01:54
jasoncool1
摘要:1 class Solution { 2 public int findLengthOfLCIS(int[] nums) { 3 if(nums.length == 0) return 0; 4 if(nums.length == 1) return 1; 5 int[] dp = new int[nums.length]; 6...
阅读全文
posted @ 2018-10-28 00:17
jasoncool1
摘要:1 class Solution { 2 public int longestValidParentheses(String s) { 3 if(s.length() == 0) return 0; 4 char[] arr = s.toCharArray(); 5 Stack stack = new Stack(); 6 ...
阅读全文
posted @ 2018-10-27 23:59
jasoncool1
摘要:1 class Solution { 2 public String customSortString(String S, String T) { 3 if(S.length() == 0 || T.length() == 0) return T; 4 int[] count = new int[26]; 5 for(int i ...
阅读全文
posted @ 2018-10-27 06:56
jasoncool1
摘要:用presum的方法 统计有多少个小于等于这个数的年龄
阅读全文
posted @ 2018-10-26 23:26
jasoncool1
摘要:https://leetcode.com/problems/accounts-merge/discuss/109158/Java-Solution-(Build-graph-+-DFS-search)
阅读全文
posted @ 2018-10-26 22:14
jasoncool1
摘要:每次都把区间放进去, 要是碰到end,就结束上一个start的区间
阅读全文
posted @ 2018-10-26 14:05
jasoncool1
摘要:1 class NumMatrix { 2 int[][] sum; 3 4 public NumMatrix(int[][] matrix) { 5 int row = matrix.length; 6 if(row > 0){ 7 int col = matrix[0].length; 8 ...
阅读全文
posted @ 2018-10-26 11:50
jasoncool1
摘要:https://leetcode.com/problems/lru-cache/discuss/45922/JAVA-Easy-Version-To-Understand!!!!
阅读全文
posted @ 2018-10-26 05:40
jasoncool1
摘要:https://leetcode.com/problems/is-graph-bipartite/discuss/115487/Java-Clean-DFS-solution-with-Explanation
阅读全文
posted @ 2018-10-24 10:25
jasoncool1
摘要:1 //New 2 class Solution { 3 public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { 4 if(root == null) return null; 5 if(root.val == p.val || root....
阅读全文
posted @ 2018-10-24 08:54
jasoncool1
摘要:1 //可以任意节点开始left+right 所以dfs的时候要每个节点都计算一下 2 class Solution { 3 int max = Integer.MIN_VALUE; 4 public int diameterOfBinaryTree(TreeNode root) { 5 if(root == null) return 0; 6 ...
阅读全文
posted @ 2018-10-24 04:36
jasoncool1
摘要:1 class Solution { 2 int max = Integer.MIN_VALUE; 3 public int maxPathSum(TreeNode root) { 4 if(root == null) return 0; 5 if(root.left == null && root.right == null) retu...
阅读全文
posted @ 2018-10-24 03:54
jasoncool1
摘要:1 public class Solution extends VersionControl { 2 public int firstBadVersion(int n) { 3 if(n == 1) return 1; 4 int lo = 1, hi = n; 5 while(lo < hi){ 6 i...
阅读全文
posted @ 2018-10-23 22:15
jasoncool1
摘要:https://leetcode.com/problems/valid-number/discuss/23738/Clear-Java-solution-with-ifs
阅读全文
posted @ 2018-10-23 11:31
jasoncool1
摘要:1 //New presum 2 class Solution { 3 public boolean checkSubarraySum(int[] nums, int k) { 4 if(k == 0){ 5 for(int i = 1; i list = new ArrayList(); 31 for(int i = ...
阅读全文
posted @ 2018-10-23 05:27
jasoncool1
摘要:1 public class BSTIterator { 2 Queue queue; 3 public void build(TreeNode root){ 4 if(root == null) return; 5 build(root.left); 6 queue.offer(root.val); 7 ...
阅读全文
posted @ 2018-10-23 01:28
jasoncool1
摘要:https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays/discuss/108231/C++Java-DP-with-explanation-O(n)
阅读全文
posted @ 2018-10-23 01:08
jasoncool1
摘要:用Trie, dp会TLE
阅读全文
posted @ 2018-10-22 13:36
jasoncool1
摘要:1 class Solution { 2 public List findAnagrams(String s, String p) { 3 List res = new ArrayList(); 4 if(s.length() == 0 || s.length() 0 ) count--; 15 end++; 16...
阅读全文
posted @ 2018-10-22 11:39
jasoncool1
摘要:https://leetcode.com/problems/minimum-window-substring/discuss/26808/Here-is-a-10-line-template-that-can-solve-most-'substring'-problems
阅读全文
posted @ 2018-10-22 04:49
jasoncool1
摘要:1 class Solution { 2 public boolean validPalindrome(String s) { 3 if(s.length() == 0) return true; 4 int i = 0, j = s.length() - 1; 5 while(i < j){ 6 if(...
阅读全文
posted @ 2018-10-22 03:48
jasoncool1
摘要:记录前面的sum https://leetcode.com/problems/subarray-sum-equals-k/discuss/102106/Java-Solution-PreSum-+-HashMap
阅读全文
posted @ 2018-10-22 03:04
jasoncool1
摘要:好难啊 https://leetcode.com/problems/regular-expression-matching/discuss/180290/JAVA-DP-solution-with-detailed-explanation
阅读全文
posted @ 2018-10-21 13:21
jasoncool1
摘要:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/discuss/108870/Most-consistent-ways-of-dealing-with-the-series-of-s
阅读全文
posted @ 2018-10-21 09:53
jasoncool1
摘要:Fancyhttps://leetcode.com/problems/task-scheduler/discuss/104496/concise-Java-Solution-O(N)-time-O(26)-space
阅读全文
posted @ 2018-10-20 14:29
jasoncool1
摘要:1 class Solution { 2 public boolean isNStraightHand(int[] hand, int W) { 3 if(W == 1) return true; 4 Arrays.sort(hand); 5 int i = 0, j = 0; 6 while(i < hand....
阅读全文
posted @ 2018-10-18 14:17
jasoncool1
摘要:1 class Solution { 2 public boolean isIsomorphic(String s, String t) { 3 if(s.length() != t.length()) return false; 4 int[] record1 = new int[200]; 5 int[] record2 = ...
阅读全文
posted @ 2018-10-18 13:29
jasoncool1
摘要:1 //从右往左 先排序一下 然后右到左进行替换 这样替换位置之前的index不会变 2 //注意一下Comparator的写法 3 class Solution { 4 public String findReplaceString(String S, int[] indexes, String[] sources, String[] targets) { 5 ...
阅读全文
posted @ 2018-10-17 12:18
jasoncool1
摘要:1 //自己简化了 100% 2 class Solution { 3 public String getHint(String secret, String guess) { 4 int bull = 0; 5 int cow = 0; 6 char[] arr1 = secret.toCharArray(); 7 ...
阅读全文
posted @ 2018-10-17 09:23
jasoncool1
摘要:找substring存在不存在可以直接用indexOf() 或者contains() 不用一个一个比 边界情况是 c abc a 这样子 b.length()/a.length() == 1 所以要+2
阅读全文
posted @ 2018-10-17 03:42
jasoncool1
摘要:跟字典序那道题一样 找出下一个 大于MAX_VALUE或者相同就return-1
阅读全文
posted @ 2018-10-09 20:28
jasoncool1
摘要:这个比较简单 https://leetcode.com/problems/trim-a-binary-search-tree/discuss/107000/Java-solution-6-liner
阅读全文
posted @ 2018-10-09 13:00
jasoncool1
摘要:common sense 直接sort 然后找citations > len-i 可以直接用一个bucket记录 然后大于N的全部记录在N上 因为hindex不可能大于N https://leetcode.com/problems/h-index/discuss/70768/Java-bucket-
阅读全文
posted @ 2018-10-09 11:42
jasoncool1
摘要:https://leetcode.com/problems/string-to-integer-atoi/discuss/4672/JAVA-Easy-Version-To-Understand!!!!!!!!!! 用sum = sum*10 + 这位数字来计算 不能直接通过-Integer.MIN
阅读全文
posted @ 2018-10-08 03:37
jasoncool1
摘要:1 class MyStack { 2 Queue queue; 3 4 /** Initialize your data structure here. */ 5 public MyStack() { 6 queue = new LinkedList(); 7 8 } 9 10 /** ...
阅读全文
posted @ 2018-10-08 01:52
jasoncool1
摘要:创一个root node, 不用什么值, TrieNode要有一个26到数组记录每个字母存不存在,再来一个isWord给每个node判断一下是不是一个word(单词最后一个node才是一个word)
阅读全文
posted @ 2018-10-08 01:22
jasoncool1
摘要:https://leetcode.com/problems/linked-list-cycle-ii/discuss/44777/Concise-JAVA-solution-based-on-slow-fast-pointers fast slow, 刚开始全部初始化为0,当作起始点
阅读全文
posted @ 2018-10-07 12:49
jasoncool1
摘要:一次遍历,用一个map记录相同的string <String, List<String>> char[]到String 用new String()
阅读全文
posted @ 2018-10-07 06:23
jasoncool1
摘要:记录一个current char, 用j循环到没有一样的为止,要是count>1的话,就把数字放进去
阅读全文
posted @ 2018-10-06 13:51
jasoncool1
摘要:1 class Solution { 2 public boolean isRectangleOverlap(int[] rec1, int[] rec2) { 3 if((rec2[0]=rec1[2] && rec2[2]>=rec1[2])) { 4 return false; 5 }else { 6 ...
阅读全文
posted @ 2018-10-02 03:53
jasoncool1

浙公网安备 33010602011771号