- 博客(4)
- 收藏
- 关注
原创 LeetCode - Majority Element
我知道可以用divide and conquer算法...但是我不会实现= = 就直接排序然后数个数了 其实排序之后第n/2个元素就是了不用数来着。。。 public int majorityElement(int[] num) { Arrays.sort(num); int count = 1; int majority = nu
2015-02-17 10:11:01 388 2
原创 LeetCode - Excel Sheet Column Number
判断string是否相同不能直接== 用equals... public int titleToNumber(String s) { int result = 0; int weight = 1; for (int i = s.length() - 1; i >= 0; i--) { char col = s.charAt(i); in
2015-02-17 10:07:17 300
原创 LeetCode - Count and Say
第一遍交的时候理解错题目意思了 还以为是读n... public String countAndSay(int n) { String result = "1"; for (int i = 1; i < n; i ++) { result = getResult(result); } return result; }
2015-02-17 10:05:04 294
原创 LeetCode - Valid Parentheses
昨天终于开始刷LeetCode的题了 按难度排序从简单开始 然后第一道题就是这道 隐约记得编译原理还是什么的课上讲用堆栈来实现 但具体的还是忘记了 看到答案才想起来是把左括号push 遇到右括号就和栈顶匹配 匹配pop不匹配就返回false public boolean isValid(String s) { Stack stack = new Stack(); cha
2015-02-17 04:23:47 345 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人