随笔分类 - Binary Search
发表于 2018-11-10 18:40阅读:351评论:0推荐:0
摘要:A positive integer is magical if it is divisible by either A or B. Return the N-th magical number. Since the answer may be very large, return it modul
阅读全文 »
发表于 2018-11-10 17:51阅读:299评论:0推荐:0
摘要:Koko loves to eat bananas. There are N piles of bananas, the i-th pile has piles[i] bananas. The guards have gone and will come back in H hours. Koko
阅读全文 »
发表于 2018-11-10 17:04阅读:277评论:0推荐:0
摘要:Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If targetexists, t
阅读全文 »
发表于 2018-11-09 21:14阅读:225评论:0推荐:0
摘要:Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[
阅读全文 »
发表于 2018-11-09 20:52阅读:300评论:0推荐:0
摘要:Let f(x) be the number of zeroes at the end of x!. (Recall that x! = 1 * 2 * 3 * ... * x, and by convention, 0! = 1.) For example, f(3) = 0 because 3!
阅读全文 »
发表于 2018-11-09 18:48阅读:183评论:0推荐:0
摘要:A sorted list A contains 1, plus some number of primes. Then, for every p < q in the list, we consider the fraction p/q. What is the K-th smallest fra
阅读全文 »
发表于 2018-11-08 20:48阅读:206评论:0推荐:0
摘要:Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pair (A, B) is defined as the absolute difference bet
阅读全文 »
发表于 2018-11-08 17:34阅读:291评论:0推荐:0
摘要:Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number quickly from the multiplication table? Given the
阅读全文 »
发表于 2018-11-08 16:34阅读:247评论:0推荐:0
摘要:Given a sorted array, two integers k and x, find the k closest elements to x in the array. The result should also be sorted in ascending order. If the
阅读全文 »
发表于 2018-11-07 21:33阅读:329评论:0推荐:0
摘要:For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1. Now given a string representing n, you should return the smallest go
阅读全文 »
发表于 2018-11-06 21:55阅读:216评论:0推荐:0
摘要:You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number
阅读全文 »
发表于 2018-11-06 21:38阅读:206评论:0推荐:0
摘要:Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point o
阅读全文 »
发表于 2018-11-06 20:28阅读:177评论:0推荐:0
摘要:Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algor
阅读全文 »
发表于 2018-11-05 17:01阅读:195评论:0推荐:0
摘要:Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is po
阅读全文 »
发表于 2018-11-05 12:11阅读:157评论:0推荐:0
摘要:Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is th
阅读全文 »
发表于 2018-11-05 09:39阅读:159评论:0推荐:0
摘要:We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wron
阅读全文 »
发表于 2018-11-05 09:24阅读:175评论:0推荐:0
摘要:Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library functio
阅读全文 »
发表于 2018-11-04 22:33阅读:271评论:0推荐:0
摘要:Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k. Example: Not
阅读全文 »
发表于 2018-11-04 11:08阅读:266评论:0推荐:0
摘要:You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit into another if and only if both the w
阅读全文 »
发表于 2018-11-03 22:38阅读:223评论:0推荐:0
摘要:A peak element is an element that is greater than its neighbors. Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return
阅读全文 »