摘要:
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note: You may a... 阅读全文
摘要:
Solution 1: Solution 2: O(N) time, O(1) space The basic idea is to find the next number to add.Take 45 for example: if the current number is 45, the n 阅读全文
摘要:
Random random = new Random(); random.nextInt(int i); 阅读全文
摘要:
using one array 阅读全文
摘要:
Solution 1: Reservior sampling: (wiki introduction) Reservoir sampling is a family of randomized algorithms for randomly choosing a sample of k items 阅读全文
摘要:
The idea is to add a set to the hashMap to remember all the locations of a duplicated number. 阅读全文
摘要:
最先想到是用double LinkedList+Map, 没必要,arraylist+map就够了;另外取random的方法还有,rand.nextInt(int n) returns an integer in the range [0, n) java.util.Random rand = ne 阅读全文