蓄水池原理应用: 随机返回n个元素中的某个元素,从0开始遍历这n个元素 用count记录遍历过得元素数目(符合要求的元素在数,比如数值等于target的数组索引),如果random(count)==0 则选中这个元素。 可以证明 在遍历的过程中 随着遍历元素数目的增加 random(count)==0 的几率是随机均等的 Given an array of integers
Olya likes milk very much. She drinks k cartons of milk each day if she has at least k and drinks all of them if she doesn’t. But there’s an issue — expiration dates. Each carton has a date after w
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it’s not that simple. There’s only one receptionist at the passpor