摘要:
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) ... 阅读全文
摘要:
public class Solution { public boolean searchMatrix(int[][] matrix, int target) { if(matrix.length==0||matrix[0].length==0) return false; int m=matrix.length; ... 阅读全文
摘要:
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--) ... 阅读全文
摘要:
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][... 阅读全文
摘要:
class Solution { public String simplifyPath(String path) { Stack stack=new Stack(); String[] strs=path.split("\\/"); for(int i=0;i<strs.length;i++) { i... 阅读全文
摘要:
class Solution { public List fullJustify(String[] words, int maxWidth) { List res=new ArrayList(); int idx=0; while(idx0) { sb.... 阅读全文
摘要:
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... 阅读全文
摘要:
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) ... 阅读全文
摘要:
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][... 阅读全文
摘要:
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];... 阅读全文
摘要:
class Solution { public ListNode rotateRight(ListNode head, int k) { ListNode preNode=new ListNode(0); preNode.next=head; ListNode p=preNode; int len=0; wh... 阅读全文
摘要:
Base on next permutation: 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
public class Solution { public boolean canJump(int[] nums) { int maxDistance=0; for(int i=0;i=nums.length-1) return true; } return false; ... 阅读全文
摘要:
public class Solution { public List spiralOrder(int[][] matrix) { List res=new ArrayList(); if(matrix.length==0||matrix[0].length==0) return res; spiralOrder(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) { ... 阅读全文