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 binary tree | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |
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 binary tree | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |
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 ArrayList<String> generateParenthesis(int n) { | |
ArrayList<String> result = new ArrayList<String>(); | |
StringBuilder sb = new StringBuilder(); | |
if(n <= 0) | |
return result; | |
dfsWorker(n, result, sb, 0, 0); | |
return result; |
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 ArrayList<ArrayList<Integer>> combine(int n, int k) { | |
ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); | |
if(n <= 0 || k<=0) | |
return result; | |
ArrayList<Integer> temp = new ArrayList<Integer>(); | |
dfsWorker(n, k, result, temp, 1); | |
return result; | |
} |
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 ArrayList<ArrayList<Integer>> combinationSum(int[] candidates, int target) { | |
if(candidates == null) | |
return null; | |
ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); | |
ArrayList<Integer> temp = new ArrayList<Integer>(); | |
if(target <= 0) | |
return result; | |
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
/* | |
*Key point: dfs, | |
* it's similar to question Subsets; however, we need all elements rather than subsets | |
* so, we have to scan from beginning of array and need a boolean array to store which element has been visited | |
*/ | |
public class Solution { | |
public ArrayList<ArrayList<Integer>> permute(int[] num) { | |
if(num == null) | |
return null; |
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 ArrayList<ArrayList<Integer>> subsetsWithDup(int[] num) { | |
if(num == null) | |
return null; | |
ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); | |
ArrayList<Integer> temp = new ArrayList<Integer>(); | |
result.add(temp); | |
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 ArrayList<ArrayList<Integer>> subsets(int[] S) { | |
if(S == null) | |
return null; | |
ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); | |
//empty set is the subset of any set | |
result.add(new ArrayList<Integer>()); | |
//sort array to statisfy the requirement of non-descending order |
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
#define a class to represent the x and y coordinates of points | |
class Point: | |
def __init__(self,x,y): | |
self.x = x | |
self.y = y | |
#judges if point A,B,C are counter-clockwise | |
def ccw(A,B,C): | |
return (C.y-A.y)*(B.x-A.x) > (B.y-A.y)*(C.x-A.x) |
NewerOlder