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 a Node. | |
class Node { | |
public int val; | |
public Node left; | |
public Node right; | |
public Node() {} | |
public Node(int _val,Node _left,Node _right) { |
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; } | |
* } | |
*/ | |
/** | |
* Definition for a binary tree node. |
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
class Solution { | |
public List<List<Integer>> combinationSum(int[] candidates, int target) { | |
if (candidates == null || candidates.length == 0) { | |
return new LinkedList<List<Integer>>(); | |
} | |
List<List<Integer>> results = new LinkedList<>(); | |
List<Integer> prefix = new LinkedList<>(); | |
recurseSum(results, prefix, 0, candidates, target); |
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; } | |
* } | |
*/ | |
class Solution { | |
public ListNode mergeKLists(ListNode[] lists) { |
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
class Solution { | |
public int minPathSum(int[][] grid) { | |
if (grid == null || grid.length == 0 || grid[0].length == 0) { | |
return 0; | |
} | |
final int rows = grid.length; | |
final int cols = grid[0].length; | |
int[][] visited = new int[rows][cols]; | |
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
class Solution { | |
public int uniquePaths(int m, int n) { | |
// m is columns | |
// n is rows | |
if (m < 1 || n < 1) { | |
return 0; | |
} | |
if (m == 1 && m == 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
class Solution { | |
public List<List<Integer>> permute(int[] nums) { | |
List<List<Integer>> results = new ArrayList<List<Integer>>(); | |
if (nums == null || nums.length == 0) { | |
return results; | |
} | |
List<Integer> prefix = new ArrayList<Integer>(); | |
permutateRecursive(nums, prefix, results); |
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
class Solution { | |
private int lo, maxLen; | |
public String longestPalindrome(String s) { | |
int len = s.length(); | |
if (len < 2) | |
return s; | |
for (int i = 0; i < len-1; i++) { | |
extendPalindrome(s, i, i); //assume odd length, try to extend Palindrome as possible |
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
class Solution { | |
public void sortColors(int[] nums) { | |
// nums value is 0, 1, 2 | |
int left = 0; | |
int right = nums.length-1 ; | |
int i = 0; | |
// move 0s and 2s so 1s will settle by themselves |
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
class Solution { | |
public List<List<Integer>> subsets(int[] nums) { | |
// check | |
if (nums == null) { | |
throw new IllegalArgumentException(); | |
} | |
List<List<Integer>> results = new LinkedList<List<Integer>>(); | |
// prepare to recursive |