摘要: 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 阅读(229) 评论(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 阅读(270) 评论(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 阅读(242) 评论(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 阅读(235) 评论(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 阅读(242) 评论(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 阅读(419) 评论(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 阅读(239) 评论(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 阅读(293) 评论(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 阅读(139) 评论(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 阅读(210) 评论(0) 推荐(0)