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
package CC150.ArraysAndString; | |
/** | |
* Implement a function reverse which reverse a null-terminated string (null-terminated only works for C/C++) | |
*/ | |
public class ReverseString { | |
public static void main(String args[]) { | |
System.out.println(reverse("hello")); | |
} | |
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
package CC150.ArraysAndString; | |
/** | |
* I misunderstand the defination of permutation. I treat it as reverse. | |
* Permutation means anyway, but reversed. abb is a permutation of bab. | |
* Permutation feature: the count of ever number is same, any combination is valid | |
*/ | |
public class Permutation { | |
public static void main(String[] args) { | |
System.out.println(permutation("fabcdfedfaaa","abacdaedfaff")); |
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
package CC150.ArraysAndString; | |
/** | |
* 1. Calculate spaces count first, then we know new char[] length | |
* 2. To prevent overlap, start replace from end to head | |
* | |
* true length < str.length because of input may end with many spaces. | |
* length = str.length - end spaces | |
* | |
* book use newLength - 1, then newLength--, I use step here. |
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
package leetcode; | |
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.LinkedHashMap; | |
import java.util.Map; | |
import java.util.Map.Entry; | |
import java.util.Set; | |
/** |
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
package CC150.ArraysAndString; | |
/** | |
* Check if s2 is a rotation of s1 using only one call to isSubstring | |
* eg: "waterbottle" is a rotation of "erbottlewat" | |
* | |
*/ | |
public class IsRotation { | |
public boolean isRotation2(String s1, String s2) { |
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
package leetcode.combinations; | |
import java.util.ArrayList; | |
public class Combine { | |
public static void main(String args[]) { | |
System.out.println(combine(4,2)); | |
} | |
/** |
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
package leetcode.simpleCoding; | |
/** | |
* @author jeffwan | |
* @date Feb 8, 2014 | |
* | |
* Objective: write the simple and readable codes | |
* There's no algorithm in this kind of problem but some tiny simple method. Our goal is to make it as clear as possible. | |
* In addition, It's a good opportunity communicatting with interviewer about the overflow, 100 -- 001 (display). | |
* |
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
package leetcode.simpleCoding; | |
/** | |
* @date Feb 8, 2014 | |
* | |
* Test case: (1123 123) ("","") --> may OutOfBound ,("a","a") --> s1.length()- s2.length()+1 not without +1, bound check. | |
* return value: haystack.subString(i) but not String.valueOf(i) ("","" will return 0). | |
* take care | |
*/ | |
public class StrStr { |
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
package leetcode.tree; | |
import java.util.ArrayList; | |
import java.util.Stack; | |
/** | |
* Definition for binary tree | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; |
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
package leetcode.tree; | |
import java.util.ArrayList; | |
import java.util.Stack; | |
import leetcode.tree.InorderTraversal.TreeNode; | |
public class PreorderTraversal { | |
public ArrayList<Integer> preorderTraversal(TreeNode root) { |