随笔分类 -  leetcode

上一页 1 ··· 8 9 10 11 12 13 14 下一页
摘要:https://leetcode.com/problems/trapping-rain-water-ii/ // https://discuss.leetcode.com/topic/60418/java-solution-using-priorityqueue/2 // 这个解法真的好棒,真的太棒了 // 一维的也能搞定// 利用一个PriorityQueue,从小往大排的 import ... 阅读全文
posted @ 2016-09-29 16:09 blcblc 阅读(329) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/sum-of-left-leaves/ /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(in... 阅读全文
posted @ 2016-09-29 16:09 blcblc 阅读(223) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/remove-k-digits/ // 参考了这里的 // https://discuss.leetcode.com/topic/59327/o-n-solution/3 public class Solution { public String removeKdigits(String num, int k) { ... 阅读全文
posted @ 2016-09-21 04:05 blcblc 阅读(238) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/frog-jump/ // 受以下网页启发,用递归可行 // https://discuss.leetcode.com/topic/59337/easy-version-java public class Solution { Map mp; private int[] stones; public bool... 阅读全文
posted @ 2016-09-21 03:28 blcblc 阅读(440) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/nth-digit/ public class Solution { public int findNthDigit(int n) { int k = 9; int b = 1; // 需要加上对b的限制 while (b k*b) { ... 阅读全文
posted @ 2016-09-21 02:11 blcblc 阅读(131) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/binary-watch/ // 参考 https://discuss.leetcode.com/topic/59374/simple-python-java // 非常棒的方法 public class Solution { public List readBinaryWatch(int num) { Li... 阅读全文
posted @ 2016-09-21 01:49 blcblc 阅读(185) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/elimination-game/ // 一行代码就可以,不过原理有些复杂 // https://discuss.leetcode.com/topic/58042/c-1-line-solution-with-explanation // return n == 1 ? 1 : 2 * (1 + n / 2 - lastRemaini... 阅读全文
posted @ 2016-09-21 01:21 blcblc 阅读(206) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/evaluate-division/ public class Solution { private Map mp; private class Item { public String str; public double prop; public Item(Strin... 阅读全文
posted @ 2016-09-18 23:51 blcblc 阅读(253) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/random-pick-index/ public class Solution { private Map mp; private Random rand; public Solution(int[] nums) { mp = new HashMap(); for ... 阅读全文
posted @ 2016-09-18 10:41 blcblc 阅读(229) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/integer-replacement/ // 除了首位的1,其他的1需要2次操作,0需要1次操作。 // 所以尽量把1变成0 // 所以,3直接得出结果2, // 其他的,01->-1,11->+1 public class Solution { public int integerReplacement(int inn)... 阅读全文
posted @ 2016-09-18 00:00 blcblc 阅读(216) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/rotate-function/ public class Solution { public int maxRotateFunction(int[] A) { int all = 0; int sum = 0; int ret = Integer.MIN_VALUE; ... 阅读全文
posted @ 2016-09-17 22:55 blcblc 阅读(226) 评论(0) 推荐(0)
摘要:public class Solution { public int longestSubstring(String s, int k) { // Find count of each char HashMap mp = new HashMap(); Object intObj; for (int 阅读全文
posted @ 2016-09-17 18:52 blcblc 阅读(399) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/decode-string/ public class Solution { private String s; private int newPos; public String decodeString(String ins) { s = '.' + ins + ']'; ... 阅读全文
posted @ 2016-09-17 15:38 blcblc 阅读(219) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/utf-8-validation/ public class Solution { public boolean validUtf8(int[] data) { int last = 0; for (int i=0; i 0) { if (str.length()... 阅读全文
posted @ 2016-09-16 23:06 blcblc 阅读(274) 评论(0) 推荐(0)
摘要:public class Solution { public boolean isSubsequence(String s, String t) { int idx = 0; for (int i=0; i<t.length()&&idx<s.length(); i++) { if (s.charAt(idx) == t.charA... 阅读全文
posted @ 2016-09-16 22:41 blcblc 阅读(122) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/perfect-rectangle/ // https://discuss.leetcode.com/topic/55944/o-n-log-n-sweep-line-solution public class Solution { public class Column implements Comparabl... 阅读全文
posted @ 2016-08-30 19:49 blcblc 阅读(191) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/find-the-difference/ public class Solution { public char findTheDifference(String s, String t) { char[] sch = s.toCharArray(); char[] tch = t.toChar... 阅读全文
posted @ 2016-08-30 17:13 blcblc 阅读(183) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/longest-absolute-file-path/ public class Solution { public int lengthLongestPath(String input) { Stack stk = new Stack(); int left = 0; int ... 阅读全文
posted @ 2016-08-30 01:05 blcblc 阅读(200) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/first-unique-character-in-a-string/ public class Solution { public int firstUniqChar(String s) { int[] index = new int[26]; for (int i=0; i 0) { ... 阅读全文
posted @ 2016-08-29 11:59 blcblc 阅读(250) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/lexicographical-numbers/ public class Solution { public List lexicalOrder(int n) { List ret = new ArrayList(); int cur = 1; ret.add(cur); ... 阅读全文
posted @ 2016-08-29 00:23 blcblc 阅读(173) 评论(0) 推荐(0)

上一页 1 ··· 8 9 10 11 12 13 14 下一页