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
| /* | |
| * mergeTwoLists | |
| * Returns the head of a sorted linked list, which is created by merging two sorted linked lists. | |
| * | |
| * @author Xiang Li <[email protected]> | |
| * @param l1 the head of the first sorted linked list to be merged | |
| * @param l2 the head of the second sorted linked list to be merged | |
| * @return the head of the merged 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
| package build; | |
| import java.util.*; | |
| public class Trie { | |
| private int SIZE = 26; | |
| private TrieNode root; | |
| Trie() | |
| { | |
| root = new TrieNode(); | |
| } | |
| private class TrieNode{ |
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 BlackJackCard extends Card { | |
| public BlackJackCard(int c, Suit s) { | |
| super(c, s); | |
| } | |
| public int value() { | |
| if (isAce()) { // Ace | |
| return 1; | |
| } else if (faceValue >= 11 && faceValue <= 13) { // Face card | |
| return 10; |
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
| //1,000,000 ints find 4 missing numbers | |
| //naive way: bitset, using O(n) space | |
| static List<Integer> findmissing(int[] array) | |
| { | |
| BitSet bset = new BitSet(array.length); | |
| for(int i=0;i<array.length;++i) | |
| { | |
| bset.set(array[i]); |