`
文章列表
Input: N sorted arrays of integers (in ascending order) Output: Final sorted array of integers   public static class Node { int index = 0; List<Integer> list; public Node(List<Integer> list) { this.list = list; } public int peek() { ret ...
Given integer n, find the number of different binary strings of size n where there are no consecutive 1's.Eg: If n is 2, valid strings are 00, 01, 10. You should return 3.   假设f(n, k)是第n位上为k的数字的个数无论第n-1位是0还是1,第n位都能取0,故有:f(n, 0) = f(n-1, 0) + f(n-1, 1). 而只有在第n-1位取0时,第n位才能取1,即:f(n, 1) = f(n-1, 0)n位b ...
Take a second to imagine that you are in a room with 100 chairs arranged in a circle. These chairs are numbered sequentially from One to One Hundred. At some point in time, the person in chair #1 will be told to leave the room. The person in chair #2 will be skipped, and the person in chair #3 will ...
Implementing HashSet in Java.   public class HashSet<K> { public static class Node<K> { final K key; Node next; public Node(K key, Node next) { this.key = key; this.next = next; } } private int size = 0; private int capacity = 16; private Node[] tab; ...
Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space?   Solution 1: public boolean hasCycle(ListNode head) { ListNode walker = head, runner = head; do { if(runner == null || runner.next == null) return false ...
i18n (where 18 stands for the number of letters between the first i and the last n in the word “internationalization,”) Wiki it.    Generate all such possible i18n strings for any given string. for eg. "careercup"=>"c7p","ca6p","c6up","car5p",& ...
Suppose you have a Iterator class with has_next() and get_next() methods. Please design and implement a PeekIterator class as a wrapper of Iterator and provide a peek() method. When calling peek(), the user will only get the current element without moving forward the iterator.   Note: For Java s ...
Suppose you have a Iterator class with has_next() and get_next() methods. Please design and implement a ZigzagIterator class as a wrapper of two iterators. For example, given two iterators:i0 = [1,2,3,4]i1 = [5,6] ZigzagIterator it(i0, i1); while(it.has_next()) { print(it.get_next()); } ...
Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree.   /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : ...
Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree.   /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : v ...
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n. For example:Given n = 13,Return 6, because digit 1 occurred in the following numbers: 1, 10, 11, 12, 13.   Solution: For example '8192': 1-999 -> countDigitOne(999) 1000-199 ...
电面1: strStr() Top k frequent elements in an unsorted array FOLLOW UP: Top k frequent elements in a stream Kth most frequent number Max Array Input : An array of n numbers, and a number k Output : An array of n numbers where output = MAX(input, input[i + 1]...... input[i + ...

HashMap

1,链表法。 public class HashMap<K,V> { public static class Node<K,V> { K key; V value; Node next; public Node(K key, V value, Node<K, V> next) { this.key = key; this.value = value; this.next = next; ...
补充知识:向量叉积,向量P = (x1, y1); Q = (x2, y2); P×Q = (x1*y2 - x2*y1);叉积的一个非常重要性质是可以通过它的符号判断两矢量相互之间的顺逆时针关系:若 P × Q > 0 , 则P在Q的顺时针方向。若 P × Q < 0 , 则P在Q的逆时针方向。若 P × Q = 0 , 则P与Q共线,但可能同向也可能反向。叉积的方向与进行叉积的两个向量都垂直,所以叉积向量即为这两个向量构成平面的法向量。 我们来考虑题目,假设凸多边形各个定点坐标按照逆时针方向存储于一个数组中,那么可以通过计算0-i与0-P两个向量之间的左右关系确定点P于某两个 ...
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1->1->2->3, return 2->3.   public ListNode deleteDuplicates(ListNod ...
Global site tag (gtag.js) - Google Analytics