Skip to content

Instantly share code, notes, and snippets.

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++)
{
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;
}
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++)
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
@guolinaileen
guolinaileen / Add Binary.java
Last active December 14, 2015 06:48
careful about the character and integer
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)
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;}
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;
}
@guolinaileen
guolinaileen / Sqrt(x).java
Last active December 14, 2015 04:28
need to take care of overflow, so use division instead of multiply.
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)))
{
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 ;
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;