This file contains hidden or 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) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
int m=obstacleGrid.length; | |
int n=obstacleGrid[0].length; | |
if(m<=0 || n<=0) return 0; | |
int [][]matrix=new int [m][n]; | |
for(int i=0; i<n; i++) | |
{ |
This file contains hidden or 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) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
if(m<=0 || n<=0) return 0; | |
int [][]matrix=new int [m][n]; | |
for(int i=0; i<n; i++) | |
{ | |
matrix[0][i]=1; | |
} |
This file contains hidden or 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) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
int m=grid.length; if(m==0) return 0; | |
int n=grid[0].length; if(n==0) return 0; | |
int [][]matrix=new int [m][n]; | |
for(int i=0; i<m; i++) | |
{ | |
for(int j=0; j<n; j++) |
This file contains hidden or 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 singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode(int x) { | |
* val = x; | |
* next = null; | |
* } | |
* } |
This file contains hidden or 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 String addBinary(String a, String b) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
String result=""; | |
if(a.length()==0) return b; | |
if(b.length()==0) return a; | |
int i=a.length()-1, j=b.length()-1; | |
int carry=0; | |
while(i>=0 || j>=0 || carry!=0) |
This file contains hidden or 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[] plusOne(int[] digits) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
int length=digits.length; | |
if(length==0) return digits; | |
boolean flag=true; | |
for(int i=0; i<length; i++) | |
{ | |
if(digits[i]!=9) {flag=false; break;} |
This file contains hidden or 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 ArrayList<String> fullJustify(String[] words, int L) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
ArrayList<String> result=new ArrayList<String>(); | |
if(L==0 || words.length==0) | |
{ | |
result.add(""); | |
return result; | |
} |
This file contains hidden or 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 sqrt(int x) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
if(x<0) return -1; | |
if(x==0) return 0; | |
int pre=1; | |
int current=2; | |
while(!(current<=x/current && (current+1)>x/(current+1))) | |
{ |
This file contains hidden or 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 climbStairs(int n) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
int []ways=new int[n+1]; | |
return climb(ways, n); | |
} | |
int climb(int []ways, int n) | |
{ | |
if(n<0) return 0 ; |
This file contains hidden or 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 String simplifyPath(String path) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
if(path.equals("")) return path; | |
Stack<String> st=new Stack<String>(); | |
String [] array=path.split("/"); | |
for(int i=0; i<array.length; i++) | |
{ | |
if(array[i].isEmpty()||array[i].equals(".")) continue; |