This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int uniquePaths(int m, int n) { | |
int dp[][] = new int[m][n]; | |
dp[0][0] = 0; | |
for(int i=0;i<m;i++){ | |
dp[i][0] = 1; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int minPathSum(int[][] grid) { | |
int m=grid.length; | |
int n=grid[0].length; | |
int dp[][] = new int[m][n]; | |
dp[0][0]=grid[0][0]; | |
for(int i=1;i<n;i++){ | |
dp[0][i]=dp[0][i-1]+grid[0][i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int calculateMinimumHP(int[][] dungeon) { | |
int m=dungeon.length; | |
int n=dungeon[0].length; | |
int dp[][] = new int[m][n]; | |
dp[m-1][n-1] = Math.max(1-dungeon[m-1][n-1],1); | |
for(int i=n-2;i>=0;i--){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int uniquePathsWithObstacles(int[][] obstacleGrid) { | |
int m=obstacleGrid.length; | |
int n=obstacleGrid[0].length; | |
int dp[][] = new int[m][n]; | |
if(obstacleGrid[0][0]==1){ | |
dp[0][0] = 0; | |
return 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
private ArrayList<String> res = new ArrayList<String>(); | |
public List<String> letterCombinations(String digits) { | |
int length = digits.length(); | |
if(length==0) return res; | |
String[] str = {"", "", "abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; | |
helper(0, digits, str, ""); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public List<Integer> grayCode(int n) { | |
ArrayList<Integer> res = new ArrayList<Integer>(); | |
res.add(0); | |
for(int i=0;i<n;i++){ | |
int add = 1<<i; | |
int k = res.size()-1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
private ArrayList<List<Integer>> res = new ArrayList<List<Integer>>(); | |
private ArrayList<Integer> sumr = new ArrayList<Integer>(); | |
public List<List<Integer>> combinationSum(int[] candidates, int target) { | |
helper(candidates, target, sumr,0); | |
return res; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
private ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>(); | |
public List<List<Integer>> permute(int[] nums) { | |
ArrayList<Integer> set = new ArrayList<Integer>(); | |
boolean [] vis = new boolean[nums.length]; | |
helper(nums,set,vis); | |
return (List) res; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
private ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>(); | |
private HashMap hm = new HashMap(); | |
public List<List<Integer>> permuteUnique(int[] nums) { | |
ArrayList<Integer> set = new ArrayList<Integer>(); | |
boolean [] vis = new boolean[nums.length]; | |
helper(nums,set,vis); | |
return (List) res; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |
OlderNewer