随笔分类 -  LeetCode

42. Trapping Rain Water
摘要:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. 阅读全文

posted @ 2016-03-15 21:00 菜鸟2s 阅读(179) 评论(0) 推荐(0)

125. Valid Palindrome
摘要:1 public class Solution { 2 public boolean isPalindrome(String s) { 3 char[] str = s.toCharArray(); 4 if(str.length == 0) 5 return true; 6 for(int i = 阅读全文

posted @ 2016-03-12 13:07 菜鸟2s 阅读(141) 评论(0) 推荐(0)

319. Bulb Switcher
摘要:1.开始采用数组,双重for循环,毫无意外地超时了 class Solution { public: int bulbSwitch(int n) { if(n <= 0) return 0; int *b = new int[n]; for(int i = 0; i < n; ++i) b[i] = 阅读全文

posted @ 2016-03-12 12:32 菜鸟2s 阅读(153) 评论(0) 推荐(0)

326. Power of Three
摘要:递归版本: class Solution {public: bool isPowerOfThree(int n) { if(n <= 0) return false; if(n == 1) return true; else if(n%3 == 0) isPowerOfThree(n/3); els 阅读全文

posted @ 2016-03-12 11:28 菜鸟2s 阅读(152) 评论(0) 推荐(0)

导航