上一页 1 2 3 4 5 6 7 8 9 ··· 17 下一页
摘要: class Solution { public int calculate(String s) { s = s.replace(" ", "")+'+'; //Add a '+' or '-' is necessary, otherwise, the case (1+1) will return 0 阅读全文
posted @ 2022-03-29 14:03 阳光明媚的菲越 阅读(28) 评论(0) 推荐(0) 编辑
摘要: 这道题跟227题,背下来! Iterative: class Solution { public int calculate(String s) { s=s.replace(" ", "")+'+'; Stack<Integer> stk = new Stack<>(); int sign =1; 阅读全文
posted @ 2022-03-29 13:12 阳光明媚的菲越 阅读(18) 评论(0) 推荐(0) 编辑
摘要: Using Binary Search Template: class Solution { public int minEatingSpeed(int[] piles, int h) { int l=1, r=0; for(int i=0;i<piles.length;i++){ r = Math 阅读全文
posted @ 2022-03-24 05:47 阳光明媚的菲越 阅读(15) 评论(0) 推荐(0) 编辑
摘要: class Solution { public int minFlipsMonoIncr(String s) { int oneNum = 0, flipNum =0; int res =0; for(char c: s.toCharArray()){ if(c=='0'){ if(oneNum== 阅读全文
posted @ 2022-03-22 06:09 阳光明媚的菲越 阅读(12) 评论(0) 推荐(0) 编辑
摘要: By adding a 'max' and 'min' variable, we can make the solution's time complexity from O(n3) to O(n2): public long subArrayRanges(int[] nums) { long re 阅读全文
posted @ 2022-03-22 05:19 阳光明媚的菲越 阅读(31) 评论(0) 推荐(0) 编辑
摘要: Solution 1, Using a PriorityQueue class Solution { public int maximumUnits(int[][] boxTypes, int truckSize) { PriorityQueue<int[]> queue = new Priorit 阅读全文
posted @ 2022-03-22 03:53 阳光明媚的菲越 阅读(17) 评论(0) 推荐(0) 编辑
摘要: I user Trie to store the products. For every Trie node, it has the links to the next character and a PriorityQueue. The PriorityQueue is used to store 阅读全文
posted @ 2022-03-19 06:46 阳光明媚的菲越 阅读(13) 评论(0) 推荐(0) 编辑
摘要: This is a problem which check whether you know how to user Arrays.sort(). Time complexity: O(n*log(n)) Solution 1: Using comparator class Solution { p 阅读全文
posted @ 2022-03-19 03:39 阳光明媚的菲越 阅读(26) 评论(0) 推荐(0) 编辑
摘要: My first solution: 1. find lowest common ancestor of start and dest. 2. find path's length from LCA to start 3. find path from LCA to dest. 4. Combine 阅读全文
posted @ 2022-03-12 11:05 阳光明媚的菲越 阅读(64) 评论(0) 推荐(0) 编辑
摘要: The following is my first solution, very easy to understand, but brute force: For every snapshot, we clone the whole array. Time complexity of snap(): 阅读全文
posted @ 2022-03-11 05:32 阳光明媚的菲越 阅读(30) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 17 下一页