Foundation

Arrays.sort(intervals, (a, b) -> Interger.compare(a.start, b.start));

        PriorityQueue> pq = new PriorityQueue<>(
            new Comparator>() {
                @Override
                public int compare(Map.Entry a, Map.Entry b) {
                    return b.getValue() - a.getValue(); // decreasing order
                }
            }
        );

        Comparator comparator = (t1, t2) -> t2.count - t1.count;

// 必须有size
PriorityQueue queue= new PriorityQueue(lists.size(),new Comparator(){
            @Override
            public int compare(ListNode o1,ListNode o2){
                if (o1.val
class TrieNode {
    TrieNode[] children = new TrieNode[26];
    boolean isWord = false;
}

class Trie {
    private TrieNode root;
    public Trie() {
        root = new TrieNode();
    }
    public void insert(String str) {
        TrieNode cur = root;
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (cur.children[c - 'a'] == null) {
                cur.children[c - 'a'] = new TrieNode();
            }
            cur = cur.children[c - 'a'];
        }
        cur.isWord = true;
    }
    public boolean search(String str) {
        TrieNode cur = root;
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (cur.children[c - 'a'] == null) {
                return false;
            }
            cur = cur.children[c - 'a'];
        }
        return cur.isWord;
    }
    public boolean startWith(String prefix) {
        TrieNode cur = root;
        for (char c : prefix.toCharArray()) {
            if (cur.children[c - 'a'] == null) {
                return false;
            }
            cur = cur.children[c - 'a'];
        }
        return true;
    }
}

你可能感兴趣的:(Foundation)