09 2017 档案

摘要:class Solution { public int minimumTotal(List> triangle) { int[] dp=new int[triangle.size()]; for(int i=triangle.size()-1;i>=0;i--) for(int j=0;j<=i;j++) ... 阅读全文
posted @ 2017-09-30 09:48 Weiyu Wang 阅读(120) 评论(0) 推荐(0)
摘要:public class Solution { public void connect(TreeLinkNode root) { TreeLinkNode lstart=new TreeLinkNode(0); while(root!=null) { TreeLinkNode cur=lstart; ... 阅读全文
posted @ 2017-09-30 09:16 Weiyu Wang 阅读(117) 评论(0) 推荐(0)
摘要:public class Solution { public void connect(TreeLinkNode root) { TreeLinkNode startNode=root; while(startNode!=null) { TreeLinkNode node=startNode; ... 阅读全文
posted @ 2017-09-30 04:54 Weiyu Wang 阅读(126) 评论(0) 推荐(0)
摘要:class Solution { public int numDistinct(String s, String t) { int[][] dp=new int[t.length()+1][s.length()+1]; for(int i=0;i<=t.length();i++) for(int j=i;j<=s.length();... 阅读全文
posted @ 2017-09-30 04:44 Weiyu Wang 阅读(121) 评论(0) 推荐(0)
摘要:class Solution { public void flatten(TreeNode root) { TreeNode cur=root, pre=null; while(cur!=null) { if(cur.left!=null) { pre=cur.... 阅读全文
posted @ 2017-09-30 04:06 Weiyu Wang 阅读(143) 评论(0) 推荐(0)
摘要:class Solution { public List> pathSum(TreeNode root, int sum) { List> res=new ArrayList>(); pathSum(root, sum, new ArrayList(), res); return res; } private void pa... 阅读全文
posted @ 2017-09-30 02:22 Weiyu Wang 阅读(127) 评论(0) 推荐(0)
摘要:class Solution { ListNode lnode=null; public TreeNode sortedListToBST(ListNode head) { int size=0; ListNode p=head; while(p!=null) { p=p.next; ... 阅读全文
posted @ 2017-09-30 02:08 Weiyu Wang 阅读(155) 评论(0) 推荐(0)
摘要:public class Solution { public TreeNode buildTree(int[] inorder, int[] postorder) { return buildTree(inorder, 0, inorder.length-1, postorder, 0, postorder.length-1); } private TreeNo... 阅读全文
posted @ 2017-09-29 12:30 Weiyu Wang 阅读(112) 评论(0) 推荐(0)
摘要:public class Solution { public TreeNode buildTree(int[] preorder, int[] inorder) { return buildTree(preorder, 0, preorder.length-1, inorder, 0, inorder.length); } private TreeNode bu... 阅读全文
posted @ 2017-09-29 12:12 Weiyu Wang 阅读(119) 评论(0) 推荐(0)
摘要:class Solution { public List> zigzagLevelOrder(TreeNode root) { List> res=new ArrayList>(); if(root==null) return res; Queue queue=new LinkedList(); Li... 阅读全文
posted @ 2017-09-29 11:36 Weiyu Wang 阅读(122) 评论(0) 推荐(0)
摘要:class Solution { public List> levelOrder(TreeNode root) { List> res=new ArrayList>(); if(root==null) return res; Queue queue=new LinkedList(); queue.ad... 阅读全文
posted @ 2017-09-29 11:27 Weiyu Wang 阅读(124) 评论(0) 推荐(0)
摘要:class Solution { public void recoverTree(TreeNode root) { TreeNode cur=root,pre=null,node1=null,node2=null, p=null; while(cur!=null) { if(cur.left!=null) ... 阅读全文
posted @ 2017-09-29 10:01 Weiyu Wang 阅读(106) 评论(0) 推荐(0)
摘要:public class Solution { public boolean isValidBST(TreeNode root) { Stack stack=new Stack(); TreeNode cur=null; while(root!=null||!stack.isEmpty()) { ... 阅读全文
posted @ 2017-09-29 06:32 Weiyu Wang 阅读(144) 评论(0) 推荐(0)
摘要:class Solution { public boolean isInterleave(String s1, String s2, String s3) { if(s1.length()+s2.length()!=s3.length()) return false; boolean [][] dp=new boolean[s1.l... 阅读全文
posted @ 2017-09-29 06:20 Weiyu Wang 阅读(122) 评论(0) 推荐(0)
摘要:public class Solution { public int numTrees(int n) { int[] dp=new int[n+1]; dp[0]=1; dp[1]=1; for(int i=2;i<=n;i++) for(int j=1;j<=i;j++) ... 阅读全文
posted @ 2017-09-29 02:30 Weiyu Wang 阅读(130) 评论(0) 推荐(0)
摘要:class Solution { public List generateTrees(int n) { if(n==0) return new ArrayList(); return generateTrees(1, n); } private List generateTrees(int i, int j) { ... 阅读全文
posted @ 2017-09-29 02:19 Weiyu Wang 阅读(148) 评论(0) 推荐(0)
摘要:public class Solution { public List inorderTraversal(TreeNode root) { List res=new ArrayList(); Stack stack=new Stack(); while(root!=null||!stack.isEmpty()) { ... 阅读全文
posted @ 2017-09-29 02:01 Weiyu Wang 阅读(168) 评论(0) 推荐(0)
摘要:class Solution { public List restoreIpAddresses(String s) { List res=new ArrayList(); restoreIpAddresses("", 0, 0, s, res); return res; } private void restoreIpAdd... 阅读全文
posted @ 2017-09-29 01:52 Weiyu Wang 阅读(178) 评论(0) 推荐(0)
摘要:class Solution { public ListNode reverseBetween(ListNode head, int m, int n) { ListNode pre=new ListNode(0); pre.next=head; ListNode p=pre; for(int i=0;i0) ... 阅读全文
posted @ 2017-09-28 13:23 Weiyu Wang 阅读(102) 评论(0) 推荐(0)
摘要:public class Solution { public int numDecodings(String s) { if(s.length()==0) return 0; int[] dp=new int[s.length()+1]; dp[0]=1; for(int i=0;i'0'&&s.ch... 阅读全文
posted @ 2017-09-28 13:14 Weiyu Wang 阅读(132) 评论(0) 推荐(0)
摘要:public class Solution { public List> subsetsWithDup(int[] nums) { List> res=new ArrayList>(); Arrays.sort(nums); subsetsWithDup(0, new ArrayList(), res, nums); ret... 阅读全文
posted @ 2017-09-28 12:39 Weiyu Wang 阅读(128) 评论(0) 推荐(0)
摘要:1st bit: 0->1->1->0->0->1->1->0 2nd bit: 0->0->1->1->1->1->0->0 3rd bit: 0->0->0->0->1->1->1->1 阅读全文
posted @ 2017-09-28 12:09 Weiyu Wang 阅读(149) 评论(0) 推荐(0)
摘要:class Solution { public boolean isScramble(String s1, String s2) { if(s1.length()==0||s1.equals(s2)) return true; int[] cnt=new int[128]; for(int i=0;i<s1.leng... 阅读全文
posted @ 2017-09-28 06:56 Weiyu Wang 阅读(117) 评论(0) 推荐(0)
摘要:class Solution { public ListNode partition(ListNode head, int x) { ListNode l1=new ListNode(0); ListNode l2=new ListNode(0); ListNode pre=new ListNode(0); pre.next... 阅读全文
posted @ 2017-09-28 06:32 Weiyu Wang 阅读(103) 评论(0) 推荐(0)
摘要:class Solution { public int maximalRectangle(char[][] matrix) { if(matrix.length==0||matrix[0].length==0) return 0; int[] heights=new int[matrix[0].length]; in... 阅读全文
posted @ 2017-09-28 06:24 Weiyu Wang 阅读(129) 评论(0) 推荐(0)
摘要:class Solution { public int largestRectangleArea(int[] heights) { Stack stack=new Stack(); int maxArea=0; for(int i=0;i<=heights.length;i++) { int h=i<... 阅读全文
posted @ 2017-09-28 01:51 Weiyu Wang 阅读(106) 评论(0) 推荐(0)
摘要:class Solution { public ListNode deleteDuplicates(ListNode head) { ListNode pre=new ListNode(0); pre.next=head; ListNode p=pre; while(p!=null&&p.next!=null) ... 阅读全文
posted @ 2017-09-27 11:20 Weiyu Wang 阅读(104) 评论(0) 推荐(0)
摘要:class Solution { public boolean search(int[] nums, int target) { if(nums.length==0) return false; int lo=0; int hi=nums.length-1; while(lonums[hi]) ... 阅读全文
posted @ 2017-09-27 11:10 Weiyu Wang 阅读(125) 评论(0) 推荐(0)
摘要:public class Solution { public int removeDuplicates(int[] nums) { if(nums.length nums[i-2]) nums[i++] = n; return i; } 阅读全文
posted @ 2017-09-27 05:30 Weiyu Wang 阅读(110) 评论(0) 推荐(0)
摘要:class Solution { public boolean exist(char[][] board, String word) { if(board.length==0||board[0].length==0) return false; boolean[][] used=new boolean[board.length][b... 阅读全文
posted @ 2017-09-27 05:12 Weiyu Wang 阅读(156) 评论(0) 推荐(0)
摘要:class Solution { public List> subsets(int[] nums) { List> res=new ArrayList>(); subsets(0, new ArrayList(), res, nums); return res; } private void subsets(int idx,... 阅读全文
posted @ 2017-09-27 05:02 Weiyu Wang 阅读(175) 评论(0) 推荐(0)
摘要:class Solution { public List> combine(int n, int k) { List> res=new ArrayList>(); combine(n, k, new ArrayList(), res); return res; } private void combine(int num, ... 阅读全文
posted @ 2017-09-27 04:57 Weiyu Wang 阅读(142) 评论(0) 推荐(0)
摘要:class Solution { public String minWindow(String s, String t) { boolean[] chs=new boolean[128]; int[] cnt=new int[128]; for(int i=0;i0&&r0) count--; ... 阅读全文
posted @ 2017-09-27 04:38 Weiyu Wang 阅读(128) 评论(0) 推荐(0)
摘要:public class Solution { public void sortColors(int[] nums) { int lo=0; int hi=nums.length-1; int idx=0; while(idx<=hi) { if(nums[idx]==0) ... 阅读全文
posted @ 2017-09-26 12:01 Weiyu Wang 阅读(97) 评论(0) 推荐(0)
摘要:public class Solution { public boolean searchMatrix(int[][] matrix, int target) { if(matrix.length==0||matrix[0].length==0) return false; int m=matrix.length; ... 阅读全文
posted @ 2017-09-26 11:43 Weiyu Wang 阅读(102) 评论(0) 推荐(0)
摘要:public class Solution { public void setZeroes(int[][] matrix) { if(matrix.length==0||matrix[0].length==0) return; boolean row0=false; for(int i=0;i=0;i--) ... 阅读全文
posted @ 2017-09-26 11:36 Weiyu Wang 阅读(135) 评论(0) 推荐(0)
摘要:class Solution { public int minDistance(String word1, String word2) { int[][] dp=new int[word1.length()+1][word2.length()+1]; for(int i=0;i<=word1.length();i++) dp[i][... 阅读全文
posted @ 2017-09-26 10:52 Weiyu Wang 阅读(131) 评论(0) 推荐(0)
摘要:class Solution { public String simplifyPath(String path) { Stack stack=new Stack(); String[] strs=path.split("\\/"); for(int i=0;i<strs.length;i++) { i... 阅读全文
posted @ 2017-09-26 06:27 Weiyu Wang 阅读(128) 评论(0) 推荐(0)
摘要:class Solution { public List fullJustify(String[] words, int maxWidth) { List res=new ArrayList(); int idx=0; while(idx0) { sb.... 阅读全文
posted @ 2017-09-26 06:19 Weiyu Wang 阅读(137) 评论(0) 推荐(0)
摘要:class Solution { public boolean isNumber(String s) { s=s.trim(); int idx=s.indexOf('e'); if(idx>0) return isNum(s.substring(0,idx), false)&&isNum(s.substring(i... 阅读全文
posted @ 2017-09-26 05:32 Weiyu Wang 阅读(146) 评论(0) 推荐(0)
摘要:class Solution { public int minPathSum(int[][] grid) { for(int i=0;i0&&j>0) grid[i][j]+=Math.min(grid[i-1][j],grid[i][j-1]); else if(j>0) ... 阅读全文
posted @ 2017-09-26 05:11 Weiyu Wang 阅读(108) 评论(0) 推荐(0)
摘要:class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { for(int i=0;i=0?1:0; for(int i=0;i=0) obstacleGrid[i][j]+=(i>0&&obstacleGrid[i-1][... 阅读全文
posted @ 2017-09-26 04:56 Weiyu Wang 阅读(139) 评论(0) 推荐(0)
摘要:class Solution { public int uniquePaths(int m, int n) { int[][] dp=new int[m][n]; dp[0][0]=1; for(int i=0;i0?dp[i-1][j]:0)+(j>0?dp[i][j-1]:0); return dp[m-1][n-1];... 阅读全文
posted @ 2017-09-26 04:47 Weiyu Wang 阅读(82) 评论(0) 推荐(0)
摘要:class Solution { public ListNode rotateRight(ListNode head, int k) { ListNode preNode=new ListNode(0); preNode.next=head; ListNode p=preNode; int len=0; wh... 阅读全文
posted @ 2017-09-26 04:37 Weiyu Wang 阅读(114) 评论(0) 推荐(0)
摘要:Base on next permutation: 阅读全文
posted @ 2017-09-26 03:56 Weiyu Wang 阅读(141) 评论(0) 推荐(0)
摘要:class Solution { public int[][] generateMatrix(int n) { int[][] matrix=new int[n][n]; generateMatrix(0, 0, 0, n-1, n-1, matrix); return matrix; } private void gene... 阅读全文
posted @ 2017-09-26 02:25 Weiyu Wang 阅读(121) 评论(0) 推荐(0)
摘要:class Solution { public List insert(List intervals, Interval newInterval) { int idx=0; while(idx res=new ArrayList(); int start=intervals.get(0).start; int end=int... 阅读全文
posted @ 2017-09-26 02:11 Weiyu Wang 阅读(129) 评论(0) 推荐(0)
摘要:class Solution { public List merge(List intervals) { List res=new ArrayList(); if(intervals.size()==0) return res; Collections.sort(intervals, (a,b)->a.start-b... 阅读全文
posted @ 2017-09-26 02:00 Weiyu Wang 阅读(123) 评论(0) 推荐(0)
摘要:public class Solution { public boolean canJump(int[] nums) { int maxDistance=0; for(int i=0;i=nums.length-1) return true; } return false; ... 阅读全文
posted @ 2017-09-26 01:49 Weiyu Wang 阅读(141) 评论(0) 推荐(0)
摘要:public class Solution { public List spiralOrder(int[][] matrix) { List res=new ArrayList(); if(matrix.length==0||matrix[0].length==0) return res; spiralOrder(0... 阅读全文
posted @ 2017-09-26 01:44 Weiyu Wang 阅读(135) 评论(0) 推荐(0)
摘要:class Solution { public int totalNQueens(int n) { int[][] board=new int[n][n]; return totalNQueens(0, board); } private int totalNQueens(int i, int[][] board) { ... 阅读全文
posted @ 2017-09-26 01:12 Weiyu Wang 阅读(159) 评论(0) 推荐(0)
摘要:class Solution { public List> solveNQueens(int n) { int[][] board=new int[n][n]; List> res=new ArrayList>(); nQueens(0,board,res); return res; } private vo... 阅读全文
posted @ 2017-09-25 12:45 Weiyu Wang 阅读(174) 评论(0) 推荐(0)
摘要:public class Solution { public double myPow(double x, int n) { if(n==0) return 1; if(n < 0) return 1/(x*myPow(x, -(n+1))); double t = myPow(x,n/2)... 阅读全文
posted @ 2017-09-25 09:17 Weiyu Wang 阅读(154) 评论(0) 推荐(0)
摘要:class Solution { public List> groupAnagrams(String[] strs) { Map> map=new HashMap>(); for(String str: strs) { char[] arr=str.toCharArray(); Arrays.... 阅读全文
posted @ 2017-09-25 08:59 Weiyu Wang 阅读(116) 评论(0) 推荐(0)
摘要:class Solution { public void rotate(int[][] matrix) { int n=matrix.length; for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) swap(matrix,i,j,j,i); fo... 阅读全文
posted @ 2017-09-25 08:54 Weiyu Wang 阅读(118) 评论(0) 推荐(0)
摘要:public class Solution { public List> permuteUnique(int[] nums) { List> ret=new ArrayList>(); Arrays.sort(nums); boolean[] used=new boolean[nums.length]; permute(ne... 阅读全文
posted @ 2017-09-25 08:07 Weiyu Wang 阅读(128) 评论(0) 推荐(0)
摘要:public class Solution { public List> permute(int[] nums) { List> ret=new ArrayList>(); permute(new ArrayList(),ret,nums); return ret; } private void permute(List l... 阅读全文
posted @ 2017-09-25 07:51 Weiyu Wang 阅读(141) 评论(0) 推荐(0)
摘要:class Solution { public int jump(int[] nums) { int steps=0; int max=0; int cur=0; for(int i=0;i<nums.length-1;i++) { cur=Math.max(cur, i+nums[i... 阅读全文
posted @ 2017-09-25 07:41 Weiyu Wang 阅读(99) 评论(0) 推荐(0)
摘要:class Solution { public boolean isMatch(String s, String p) { boolean[][] dp=new boolean[p.length()+1][s.length()+1]; dp[0][0]=true; for(int i=1;i0&&(p.charAt(i-1)==s.char... 阅读全文
posted @ 2017-09-25 02:01 Weiyu Wang 阅读(109) 评论(0) 推荐(0)
摘要:public class Solution { public String multiply(String num1, String num2) { int[] digits=new int[num1.length()+num2.length()]; for(int i=0;i=0;i--) { if(i>0) ... 阅读全文
posted @ 2017-09-24 14:04 Weiyu Wang 阅读(150) 评论(0) 推荐(0)
摘要:class Solution { public int trap(int[] height) { int sum=0; int l=0; int r=height.length-1; int left=0; int right=0; while(lleft) ... 阅读全文
posted @ 2017-09-24 13:15 Weiyu Wang 阅读(94) 评论(0) 推荐(0)
摘要:class Solution { public int firstMissingPositive(int[] nums) { int i=0; while(i0&&nums[i]<=nums.length&&nums[i]!=nums[nums[i]-1]) { int tmp=nums[i]; ... 阅读全文
posted @ 2017-09-24 13:03 Weiyu Wang 阅读(111) 评论(0) 推荐(0)
摘要:class Solution { public List> combinationSum2(int[] candidates, int target) { List> ret=new ArrayList>(); Arrays.sort(candidates); boolean[] used=new boolean[candidates.le... 阅读全文
posted @ 2017-09-24 04:22 Weiyu Wang 阅读(95) 评论(0) 推荐(0)
摘要:public class Solution { public List> combinationSum(int[] candidates, int target) { List> ret=new ArrayList>(); Arrays.sort(candidates); generateCombination(new ArrayList(... 阅读全文
posted @ 2017-09-24 02:39 Weiyu Wang 阅读(125) 评论(0) 推荐(0)
摘要:class Solution { public void solveSudoku(char[][] board) { boolean[][][] used=new boolean[3][9][9]; for(int i=0;i<9;i++) for(int j=0;j<9;j++) if(board[... 阅读全文
posted @ 2017-09-23 14:34 Weiyu Wang 阅读(98) 评论(0) 推荐(0)
摘要:public class Solution { public boolean isValidSudoku(char[][] board) { boolean[][][] used=new boolean[3][9][9]; for(int i=0;i<9;i++) for(int j=0;j<9;j++) ... 阅读全文
posted @ 2017-09-23 13:43 Weiyu Wang 阅读(128) 评论(0) 推荐(0)
摘要:public class Solution { public int[] searchRange(int[] nums, int target) { return new int[]{binarySearch(nums,target,true),binarySearch(nums,target,false)}; } private int binarySe... 阅读全文
posted @ 2017-09-23 13:23 Weiyu Wang 阅读(131) 评论(0) 推荐(0)
摘要:public class Solution { public int search(int[] nums, int target) { int l=0; int r=nums.length-1; while(l<r) { int m=l+(r-l)/2; if(nums[m]=... 阅读全文
posted @ 2017-09-23 13:08 Weiyu Wang 阅读(127) 评论(0) 推荐(0)
摘要:class Solution { public int longestValidParentheses(String s) { int left=-1; Stack stack=new Stack(); int ret=0; for(int i=0;i<s.length();i++) { ... 阅读全文
posted @ 2017-09-23 11:50 Weiyu Wang 阅读(142) 评论(0) 推荐(0)
摘要:class Solution { public void nextPermutation(int[] nums) { int i=nums.length-1; while(i>0&&nums[i-1]>=nums[i])i--; if(i==0) { Arrays.sort(nums); ... 阅读全文
posted @ 2017-09-23 07:33 Weiyu Wang 阅读(126) 评论(0) 推荐(0)
摘要:class Solution { public List findSubstring(String s, String[] words) { List ret=new ArrayList(); if(words.length==0||words[0].length()==0||s.length()==0) return ret; ... 阅读全文
posted @ 2017-09-23 07:18 Weiyu Wang 阅读(139) 评论(0) 推荐(0)
摘要:public class Solution { public int divide(int dividend, int divisor) { boolean isNegtive=dividend0||dividend>0&&divisor=ldivisor) { if(ldividend>=l) { ... 阅读全文
posted @ 2017-09-23 06:22 Weiyu Wang 阅读(141) 评论(0) 推荐(0)
摘要:http://blog.csdn.net/v_july_v/article/details/7041827 阅读全文
posted @ 2017-09-23 06:00 Weiyu Wang 阅读(115) 评论(0) 推荐(0)
摘要:class Solution { public ListNode reverseKGroup(ListNode head, int k) { if(head==null||k==1) return head; ListNode preNode=new ListNode(0); preNode.next=head; ... 阅读全文
posted @ 2017-09-23 05:07 Weiyu Wang 阅读(110) 评论(0) 推荐(0)
摘要:Iteration 阅读全文
posted @ 2017-09-23 02:07 Weiyu Wang 阅读(93) 评论(0) 推荐(0)
摘要:class Solution { public ListNode mergeKLists(ListNode[] lists) { PriorityQueue que=new PriorityQueue((a,b)->a.val-b.val); for(ListNode list:lists) if(list!=null) ... 阅读全文
posted @ 2017-09-23 01:51 Weiyu Wang 阅读(109) 评论(0) 推荐(0)
摘要:public class Solution { public List generateParenthesis(int n) { List ret=new ArrayList(); generateParenthesis("", 0, 2*n, ret); return ret; } void generateParenth... 阅读全文
posted @ 2017-09-23 01:41 Weiyu Wang 阅读(118) 评论(0) 推荐(0)
摘要:public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { ListNode pre=new ListNode(0); pre.next=head; ListNode p=pre,q=pre; for(int i=0;i<n... 阅读全文
posted @ 2017-09-23 01:30 Weiyu Wang 阅读(118) 评论(0) 推荐(0)
摘要:public class Solution { public List> fourSum(int[] nums, int target) { List> ret=new ArrayList>(); Arrays.sort(nums); for(int i=0;i<nums.length;i++) i... 阅读全文
posted @ 2017-09-23 01:23 Weiyu Wang 阅读(126) 评论(0) 推荐(0)
摘要:public class Solution { public List letterCombinations(String digits) { LinkedList que=new LinkedList(); if(digits.length()==0) return que; String[] btns=new S... 阅读全文
posted @ 2017-09-23 01:11 Weiyu Wang 阅读(141) 评论(0) 推荐(0)
摘要:class Solution { public int threeSumClosest(int[] nums, int target) { Arrays.sort(nums); int ret=nums[0]+nums[1]+nums[2]; for(int i=0;i<nums.length;i++) { ... 阅读全文
posted @ 2017-09-22 12:55 Weiyu Wang 阅读(122) 评论(0) 推荐(0)
摘要:class Solution { public List> threeSum(int[] nums) { List> ret=new ArrayList>(); Arrays.sort(nums); for(int i=0;i0) r--; else ... 阅读全文
posted @ 2017-09-22 12:32 Weiyu Wang 阅读(112) 评论(0) 推荐(0)
摘要:class Solution { public String intToRoman(int num) { String[][] r=new String[][]{{"","M","MM","MMM"}, {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"}, ... 阅读全文
posted @ 2017-09-22 12:12 Weiyu Wang 阅读(123) 评论(0) 推荐(0)
摘要:class Solution { public int maxArea(int[] height) { int maxArea=0; int i=0; int j=height.length-1; while(i<j) { maxArea=Math.max(maxArea,Math.m... 阅读全文
posted @ 2017-09-22 11:23 Weiyu Wang 阅读(137) 评论(0) 推荐(0)
摘要:Recursive DP 阅读全文
posted @ 2017-09-22 04:31 Weiyu Wang 阅读(169) 评论(0) 推荐(0)
摘要:class Solution { public int myAtoi(String str) { str=str.trim(); if(str.length()==0) return 0; int flag=1; int i=0; if(str.charAt(i)=='+') ... 阅读全文
posted @ 2017-09-22 02:18 Weiyu Wang 阅读(131) 评论(0) 推荐(0)
摘要:class Solution { public String convert(String s, int numRows) { if(numRows==1) return s; int divisor=(numRows-1)*2; StringBuilder sb=new StringBuilder(); ... 阅读全文
posted @ 2017-09-22 01:53 Weiyu Wang 阅读(88) 评论(0) 推荐(0)
摘要:Brutal Force: O(n^2) Manacher: O(n) 阅读全文
posted @ 2017-09-21 15:07 Weiyu Wang 阅读(146) 评论(0) 推荐(0)
摘要:public class Solution { public double findMedianSortedArrays(int[] nums1, int[] nums2) { int l=(nums1.length+nums2.length+1)>>1; int r=(nums1.length+nums2.length+2)>>1; re... 阅读全文
posted @ 2017-09-21 12:34 Weiyu Wang 阅读(153) 评论(0) 推荐(0)
摘要:class Solution { public int lengthOfLongestSubstring(String s) { Map map=new HashMap(); int maxlen=0; for(int j=0,i=0;i<s.length();i++) { char c=s.char... 阅读全文
posted @ 2017-09-21 05:52 Weiyu Wang 阅读(111) 评论(0) 推荐(0)
摘要:class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode ret=new ListNode(0); ListNode l3=ret; int carry=0; while(l1!=null||l2!=null||ca... 阅读全文
posted @ 2017-09-21 05:39 Weiyu Wang 阅读(117) 评论(0) 推荐(0)