LeetCode
文章平均质量分 54
Capr1corn
命数如织,当为磐石
展开
-
[Leetcode] 1、Two sum(两数之和)题解
Two SumGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use ...原创 2018-12-27 20:37:39 · 165 阅读 · 0 评论 -
[LeetCode]189. Rotate Array
Given an array, rotate the array to the right by k steps, where k is non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1,2...原创 2019-01-15 20:54:06 · 85 阅读 · 0 评论 -
[LeetCode]169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element alway...原创 2019-01-15 20:31:43 · 96 阅读 · 0 评论 -
[LeetCode]167. Two Sum II - Input array is sorted
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 numbers s...原创 2019-01-09 21:31:59 · 364 阅读 · 0 评论 -
[LeetCode]121. Best Time to Buy and Sell Stock(股票买卖的最佳时间)
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), ...原创 2019-01-08 20:33:26 · 153 阅读 · 0 评论 -
[LeetCode]941. Valid Mountain Array
Given an array A of integers, return true if and only if it is a valid mountain array.Recall that A is a mountain array if and only if:A.length >= 3There exists some i with 0 < i < A.lengt...原创 2019-01-18 20:13:21 · 129 阅读 · 0 评论 -
[LeetCode]118. Pascal's Triangle
Given a non-negative integer numRows, generate the first numRows of Pascal’s triangle.In Pascal’s triangle, each number is the sum of the two numbers directly above it.Example:Input: 5Output:[ ...原创 2019-01-07 20:44:46 · 119 阅读 · 0 评论 -
[LeetCode]268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.Example 1:Input: [3,0,1]Output: 2Example 2:Input: [9,6,4,2,3,5,7,0,1]Output: ...原创 2019-01-17 20:52:51 · 107 阅读 · 0 评论 -
[LeetCode]219. Contains Duplicate II
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....原创 2019-01-17 20:34:28 · 118 阅读 · 0 评论 -
[Leetcode] 35.Search Insert Position(查找插入位置) 题解
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Ex...原创 2019-01-02 20:46:28 · 117 阅读 · 0 评论 -
[LeetCode]88. Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respectively.You may assume that n...原创 2019-01-04 20:29:24 · 105 阅读 · 0 评论 -
[LeetCode]66. Plus One
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each element ...原创 2019-01-04 20:01:05 · 111 阅读 · 0 评论 -
[Leetcode] 27. Remove Element(删除元素)题解
Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array...原创 2018-12-29 18:48:14 · 115 阅读 · 0 评论 -
[Leetcode] 53. Maximum Subarray(最大子串和问题)
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanation:...原创 2019-01-03 22:29:46 · 176 阅读 · 0 评论 -
[Leetcode] 26、Remove Duplicates from Sorted Array(从有序数组中删除重复项)题解
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modifyin...原创 2018-12-28 20:47:36 · 115 阅读 · 0 评论 -
[LeetCode]217. Contains Duplicate
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...原创 2019-01-16 21:30:09 · 115 阅读 · 0 评论