随笔分类 -  leetcode

上一页 1 ··· 7 8 9 10 11 12 13 14 下一页
摘要:题目还是很好的,提供了一种新的思路方向。 细节方面,开始我的判断条件用的dict,不太好,后来debug好了。 另外,注意其中用数组初始化Set的方法:Set<String> dict = new HashSet(Arrays.asList(bank)); 还有 Set<String> a = ne 阅读全文
posted @ 2016-10-22 15:10 blcblc 阅读(737) 评论(0) 推荐(0)
摘要:下面这个链接有比较全的leetcode题目包括锁的 http://www.cnblogs.com/grandyang/p/4606334.html https://leetcode.com/problems/binary-tree-upside-down/ http://blog.csdn.net/ 阅读全文
posted @ 2016-10-20 00:12 blcblc 阅读(568) 评论(0) 推荐(0)
摘要:哈哈,我用了HashMap, 双向链表,还有了HashSet来保存key的集合。 我也把解法发到了Discuss版: https://discuss.leetcode.com/topic/63559/my-accepted-java-solution-with-hashmap-and-double- 阅读全文
posted @ 2016-10-17 18:53 blcblc 阅读(339) 评论(0) 推荐(0)
摘要:用sliding window的方法,之前还有个k不同元素好像也是类似的思路。有时间可以去复习下。 阅读全文
posted @ 2016-10-16 22:21 blcblc 阅读(966) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/reconstruct-original-digits-from-english/ //https://discuss.leetcode.com/topic/63386/one-pass-o-n-java-solution-simple-and-clear public class Solution { // zero ... 阅读全文
posted @ 2016-10-16 20:56 blcblc 阅读(663) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/third-maximum-number/ // 开始我以为相同的也占一位,比如5,3,3,2,得出3,但是答案是需要2 public class Solution { public int thirdMax(int[] nums) { List lst = new ArrayList(); ... 阅读全文
posted @ 2016-10-16 20:11 blcblc 阅读(398) 评论(0) 推荐(0)
摘要:我自己做出来的,分了几种情况来考虑。(再后面有加了注释的版本) 以下是加了注释的版本: 准备发表在Discuss版: https://discuss.leetcode.com/category/549/strong-password-checker 阅读全文
posted @ 2016-10-16 15:41 blcblc 阅读(1192) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/arithmetic-slices/ public class Solution { public int numberOfArithmeticSlices(int[] A) { if (A.length < 3) { return 0; } int... 阅读全文
posted @ 2016-10-16 14:52 blcblc 阅读(246) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/fizz-buzz/ public class Solution { public List fizzBuzz(int n) { List lst= new ArrayList(); for (int i=1; i<=n; i++) { if (i % 15 == 0... 阅读全文
posted @ 2016-10-16 14:21 blcblc 阅读(292) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/battleships-in-a-board/ // 采用的是排除法,看船的最后一个节点 public class Solution { public int countBattleships(char[][] board) { int rows = board.length; int c... 阅读全文
posted @ 2016-10-16 14:15 blcblc 阅读(275) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/ 利用了异或的”自反性“: a ^ b = c,而a ^ b ^ b = a, 则 c ^ b = a 其他运算定律有:交换律、结合律、分配律。 注意:计算使用的 阅读全文
posted @ 2016-10-16 12:23 blcblc 阅读(2706) 评论(2) 推荐(0)
摘要:https://leetcode.com/problems/pacific-atlantic-water-flow/ // 其实,这道题目可以参考前面的那道:Trapping Rain Water II // 可以看我blog上面的解法: // http://www.cnblogs.com/charlesblc/p/5920258.html // 注意Java set的操作,retai... 阅读全文
posted @ 2016-10-09 16:54 blcblc 阅读(368) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/partition-equal-subset-sum/ public class Solution { public boolean canPartition(int[] nums) { int sum = 0; for (int i=0; i<nums.length; i++) { ... 阅读全文
posted @ 2016-10-09 14:43 blcblc 阅读(366) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/add-strings/ package com.company; import java.util.LinkedList; import java.util.List; import java.util.Random; public class Main { public String addStrings(Strin... 阅读全文
posted @ 2016-10-09 14:07 blcblc 阅读(288) 评论(0) 推荐(0)
摘要:1. shuffle算法: http://www.cnblogs.com/huaping-audio/archive/2008/09/09/1287985.html 注意:我们一般用的是第二种swap的方法;但是第一种直接选择,然后把最末尾一位填上的方法,也是很好的。只是会需要两倍的空间。 2. R 阅读全文
posted @ 2016-10-07 22:28 blcblc 阅读(214) 评论(0) 推荐(0)
摘要:package com.company; import java.util.LinkedList; import java.util.List; public class Main { public int[] twoSum(int[] numbers, int target) { int i = 0, j = numbers.length - 1; ... 阅读全文
posted @ 2016-10-07 22:13 blcblc 阅读(469) 评论(0) 推荐(0)
摘要:注意,第一种用法,涉及到一些Java的知识。就是采用Object作为HashMap的key的时候,需要重载这个Class的 equals 和 hashCode 这两个方法。其中equals需要判断一下比较元素的类型,而hashCode 里面可以采用 String.valueOf(val).hashC 阅读全文
posted @ 2016-10-04 12:17 blcblc 阅读(538) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/longest-palindrome/ public class Solution { public int longestPalindrome(String s) { char []charr = s.toCharArray(); Arrays.sort(charr); int... 阅读全文
posted @ 2016-10-03 21:35 blcblc 阅读(253) 评论(0) 推荐(0)
摘要:注意这一句 经过实验,填写 (new int[][2]) 或者 (new int[][]) 都是不行的。需要在前一个下标处填写。而填写的数值范围是0到length,再大再小都不行。在这个范围内,返回的结果都是一样的。 阅读全文
posted @ 2016-09-29 17:02 blcblc 阅读(595) 评论(0) 推荐(0)
摘要:注意,以上代码里面的 >>> 是无符号位移。也就是不管正数负数,左边空出来的位都是补0. << : 左移运算符,num << 1,相当于num乘以2 >> : 右移运算符,num >> 1,相当于num除以2 >>> : 无符号右移,忽略符号位,空位都以0补齐 而C++里面的 >> 根据编译器不同有 阅读全文
posted @ 2016-09-29 16:22 blcblc 阅读(251) 评论(0) 推荐(0)

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