JasonChang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2013年11月7日

摘要: profit 可以累积 1 public class Solution { 2 public int maxProfit(int[] prices) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(prices == null) 6 return 0; 7 int result ... 阅读全文
posted @ 2013-11-07 13:05 JasonChang 阅读(159) 评论(0) 推荐(0) 编辑

摘要: bfs 1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val = x; } 8 * } 9 */10 public class Solution {11 public ArrayList> levelOrder(TreeNode root) {12 // IMPORTANT: Please re... 阅读全文
posted @ 2013-11-07 12:58 JasonChang 阅读(152) 评论(0) 推荐(0) 编辑

摘要: 找出规律 1 public class Solution { 2 public String getPermutation(int n, int k) { 3 int total = 1; 4 ArrayList rest = new ArrayList(); 5 StringBuilder result = new StringBuilder(); 6 int m = n; 7 8 while(m > 1){ 9 total*=m;10 m... 阅读全文
posted @ 2013-11-07 12:24 JasonChang 阅读(177) 评论(0) 推荐(0) 编辑

摘要: similar with Trapping rain water 1 public class Solution { 2 public int largestRectangleArea(int[] height) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int result = 0; 6 for(in... 阅读全文
posted @ 2013-11-07 12:02 JasonChang 阅读(163) 评论(0) 推荐(0) 编辑

摘要: 1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val = x; } 8 * } 9 */10 public class Solution {11 public int sumNumbers(TreeNode root) {12 // IMPORTANT: Please reset any me... 阅读全文
posted @ 2013-11-07 08:42 JasonChang 阅读(170) 评论(0) 推荐(0) 编辑

摘要: 用maxstep记录最大步程,然后遍历(greedy) 1 public class Solution { 2 public boolean canJump(int[] A) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int maxstep = 0; 6 for(int i = 0; i maxste... 阅读全文
posted @ 2013-11-07 07:18 JasonChang 阅读(185) 评论(0) 推荐(0) 编辑

摘要: 直接计算超时二分法 O(lgn) 1 public class Solution { 2 public double pow(double x, int n) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(n == 0) 6 return 1; 7 if(n == 1) 8 ... 阅读全文
posted @ 2013-11-07 06:52 JasonChang 阅读(138) 评论(0) 推荐(0) 编辑

摘要: 每个位置的水量 = 左右最大值中较小的一个 - 这个位置的高度 1 public class Solution { 2 public int trap(int[] A) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(A == null) 6 return 0; 7 int re... 阅读全文
posted @ 2013-11-07 06:46 JasonChang 阅读(204) 评论(0) 推荐(0) 编辑

摘要: 大数相乘, 按位算结果, 注意全0,注意进位 1 public class Solution { 2 public String multiply(String num1, String num2) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int length1 = num1.length(); 6 ... 阅读全文
posted @ 2013-11-07 06:30 JasonChang 阅读(167) 评论(0) 推荐(0) 编辑