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 binary tree | |
| * public class TreeNode { | |
| * int val; | |
| * TreeNode left; | |
| * TreeNode right; | |
| * TreeNode(int x) { val = x; } | |
| * } | |
| */ | |
| public class Solution { |
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
| /* | |
| Given a collection of numbers that might contain duplicates, return all possible unique permutations. | |
| For example, | |
| [1,1,2] have the following unique permutations: | |
| [1,1,2], [1,2,1], and [2,1,1]. | |
| */ | |
| public class Solution { | |
| public boolean[] used; | |
| public ArrayList<ArrayList<Integer>> permuteUnique(int[] num) { |
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 binary tree | |
| * public class TreeNode { | |
| * int val; | |
| * TreeNode left; | |
| * TreeNode right; | |
| * TreeNode(int x) { val = x; } | |
| * } | |
| */ | |
| public class Solution { |
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
| /** | |
| * Given a sorted linked list, delete all duplicates such that each element appear only once. | |
| For example, | |
| Given 1->1->2, return 1->2. | |
| Given 1->1->2->3->3, return 1->2->3. | |
| * Definition for singly-linked list. | |
| * public class ListNode { | |
| * int val; | |
| * ListNode next; |
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
| /* | |
| Given a string s, partition s such that every substring of the partition is a palindrome. | |
| Return all possible palindrome partitioning of s. | |
| For example, given s = "aab", | |
| Return | |
| [ | |
| ["aa","b"], | |
| ["a","a","b"] |
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
| /* | |
| Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. | |
| An example is the root-to-leaf path 1->2->3 which represents the number 123. | |
| Find the total sum of all root-to-leaf numbers. | |
| For example, | |
| 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
| /* | |
| Given an unsorted array of integers, find the length of the longest consecutive elements sequence. | |
| For example, | |
| Given [100, 4, 200, 1, 3, 2], | |
| The longest consecutive elements sequence is [1, 2, 3, 4]. Return its length: 4. | |
| */ | |
| public class Solution { | |
| public int longestConsecutive(int[] num) { |
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
| /* | |
| Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: | |
| Only one letter can be changed at a time | |
| Each intermediate word must exist in the dictionary | |
| For example, | |
| Given: | |
| start = "hit" | |
| end = "cog" |
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
| /* | |
| Given a collection of intervals, merge all overlapping intervals. | |
| For example, | |
| Given [1,3],[2,6],[8,10],[15,18], | |
| return [1,6],[8,10],[15,18] | |
| */ | |
| /** | |
| * Definition for an interval. |
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
| /* | |
| Given a sorted integer array and a key, output its indices’ range. | |
| For example, | |
| [5, 7, 7, 8, 8, 10] –> Given 8, outputs [3, 4] | |
| */ | |
| public class Untitled { | |
| // get a range of position of sorted array | |
| public int[] getRange(int[] input, int target) { | |
| int upper = getUpperBound(input, target); |