不为成仙,只为在这红尘中等你回来。

74.Search a 2D Matrix [Medium] [Array | Binary Search]

    ### 题意 Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: 编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性: - Integers in each row are sorted from left to right. - 每行中的整数从左到右按升序排列...

    阅读全文>>

2020年11月7日 16:28 作者:nancy 分类:[LeetCode] 1533

167. Two Sum II - Input array is sorted [Easy] [Array | Two Pointers]

    ### 题意 Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. 给定一个已按照升序排列的有序数组,找到两个数使得它们相加之和等于目标数。 The function twoSum should return indices of the two numbe...

    阅读全文>>

2018年5月4日 22:56 作者:nancy 分类:[LeetCode] 1270

485. Max Consecutive Ones [Easy] [Array]

    ### 题意 Given a binary array, find the maximum number of consecutive 1s in this array. 给定一个二进制数组, 计算其中最大连续 1 的个数。 Example 1: ```python Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecut...

    阅读全文>>

2018年4月26日 21:33 作者:nancy 分类:[LeetCode] 1272

448. Find All Numbers Disappeared in an Array [Easy] [Array]

    ### 题意 Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. 给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次。 Find all the elements of [1, n] inclusive that do...

    阅读全文>>

2018年4月26日 21:09 作者:nancy 分类:[LeetCode] 1326

414. Third Maximum Number [Easy] [Array]

    ### 题意 Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). 给定一个非空数组,返回此数组中第三大的数。如果不存在,则返回数组中最大的数。要求算法时间复杂度必须是O(n)。 Example...

    阅读全文>>

2018年4月25日 22:40 作者:nancy 分类:[LeetCode] 1383

283. Move Zeroes [Easy] [Array]

    ### 题意 Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. 给定一个数组 nums, 编写一个函数将所有 0 移动到它的末尾,同时保持非零元素的相对顺序。 For example, given nums = [0, 1, 0, 3, 12], after c...

    阅读全文>>

2018年4月24日 23:21 作者:nancy 分类:[LeetCode] 1291

268. Missing Number [Easy] [Array]

    ### 题意 Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. 给定一个包含 0, 1, 2, ..., n 中 n 个不同数字的数组,找出数组中缺少的那个数字。 Example 1 ``` Input: [3,0,1] Output: 2 ``` Example 2 ``...

    阅读全文>>

2018年4月4日 22:31 作者:nancy 分类:[LeetCode] 1348

219. Contains Duplicate II [Easy] [Array]

    ### 题意 Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k. 给定一个数组,和一个整数 k,判断该数组中是否存在不同的索引 i 和 j...

    阅读全文>>

2018年4月3日 22:50 作者:nancy 分类:[LeetCode] 1279

217. Contains Duplicate [Easy] [Array]

    ### 题意 Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. 给定一个整数数组,查找数组是否包含任何重复项。 如...

    阅读全文>>

2018年4月2日 22:56 作者:nancy 分类:[LeetCode] 1267

189. Rotate Array 【Easy】【Array】

    ### 题意 Given an array, rotate the array to the right by k steps, where k is non-negative. 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。 Example 1: ```python Input: [1,2,3,4,5,6,7] and k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to ...

    阅读全文>>

2018年4月1日 22:39 作者:nancy 分类:[LeetCode] 1309