摘要:
找出规律 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... 阅读全文
摘要:
找出规律 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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
用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... 阅读全文
摘要:
直接计算超时二分法 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 ... 阅读全文
摘要:
每个位置的水量 = 左右最大值中较小的一个 - 这个位置的高度 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... 阅读全文
摘要:
大数相乘, 按位算结果, 注意全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 ... 阅读全文
摘要:
simple recursion problem 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 boolean isSameTree(TreeNode p, TreeNode q) {12 ... 阅读全文
摘要:
slowrunner and fastrunner trick 1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) { 7 * val = x; 8 * next = null; 9 * }10 * }11 */12 public class Solution {13 public ListNode dele... 阅读全文
摘要:
similar withRemove Duplicates from Sorted Array 1 public class Solution { 2 public int removeDuplicates(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 ... 阅读全文
|