LeetCode Search a 2D Matrix II Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in... Read More

# Tag Archives: 二分搜索

# LeetCode Search a 2D Matrix

LeetCode Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first integer of each row is greater than the last... Read More

# LeetCode Find Peak Element

LeetCode Find Peak Element A peak element is an element that is greater than its neighbors. Given an input array where num ≠ num, find a peak element and return its index. The array may contain multiple peaks, in that case return the index to any one... Read More

# LeetCode Arranging Coins

LeetCode Arranging Coins 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 of full staircase rows that can be formed. n is a non-negative integer and... Read More

# LeetCode Sqrt(x)

LeetCode Sqrt(x) Implement int sqrt(int x). Compute and return the square root of x. 本题要对一个数开平方根。相当于LeetCode Valid Perfect Square的逆过程，很多方法都可以通用。 解法1。直接借用LeetCode Valid Perfect... Read More

# LeetCode Valid Perfect Square

LeetCode Valid Perfect Square 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 function such as sqrt. Example 1: Input: 16 Returns: True Example 2: Input:... Read More

# LeetCode Longest Increasing Subsequence

LeetCode Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest increasing subsequence. For example, Given , The longest increasing subsequence is , therefore the length is 4. Note that there may be more than one... Read More

# LeetCode Search in Rotated Sorted Array II

LeetCode Search in Rotated Sorted Array II Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose an array sorted in ascending order is rotated at some pivot... Read More

# LeetCode Search in Rotated Sorted Array

LeetCode Search in Rotated Sorted Array Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array... Read More

# LeetCode Find Minimum in Rotated Sorted Array II

LeetCode Find Minimum in Rotated Sorted Array II Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose an array sorted in ascending order is rotated at some... Read More