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
head->1->2->3->1->4->NULL | |
head->1->2->3->4->NULL | |
Given a reference to the head of a linked list, write a function that removes duplicates. | |
/** | |
* Definition for singly-linked list. |
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
public class Solution { | |
public List<List<Integer>> permute(int[] num) { | |
boolean[] used = new boolean[num.length]; | |
for (int i = 0; i < used.length; i ++) used[i] = false; | |
List<List<Integer>> output = new ArrayList<List<Integer>>(); | |
ArrayList<Integer> temp = new ArrayList<Integer>(); | |
permuteHelper(num, 0, used, output, temp); | |
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 sorted integer arrays A and B, merge B into A as one sorted array. | |
Note: | |
You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B are m and n respectively. | |
*/ | |
public class Solution { | |
public void merge(int A[], int m, int B[], int n) { | |
int indexInsert = m + n - 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
/** | |
* 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
public class Solution { | |
public int sqrt(int x) { | |
long low = 1; | |
long high = x/2; | |
if (x == 0){ | |
return 0; | |
} | |
if (x < 4){ | |
return 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 compareVersion(String version1, String version2) { | |
int retval = 0; | |
String[] strArray1 = version1.split("[.]"); | |
String[] strArray2 = version2.split("[.]"); | |
for (int i = 0; i < Math.max(strArray1.length, strArray2.length); i++){ | |
int val1 = (i < strArray1.length ? Integer.parseInt(strArray1[i]) : 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
class MinStack { | |
Stack<Integer> stk= new Stack<Integer>(); | |
Stack<Integer> min= new Stack<Integer>(); | |
public void push(int x) { | |
if (min.empty()){ | |
min.push(x); | |
} | |
else{ |
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; } | |
* } | |
*/ | |
/** | |
* Definition for binary tree |