209. Minimum Size Subarray Sum

2018-08-29
阅读 2 分钟
1.7k
Given an array of n positive integers and a positive integer s, findthe minimal length of a contiguous subarray of which the sum ≥ s. Ifthere isn't one, return 0 instead.Example: Input: s = 7, nums = [2,3,1,2,4,3] Output: 2 Explanation: the subarray[4,3] has the minimal length under the problem c...

485. Max Consecutive Ones

2018-08-29
阅读 1 分钟
1.5k
Given a binary array, find the maximum number of consecutive 1s inthis array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first twodigits or the last three digits are consecutive 1s. {代码...} The input array will only contain 0 and 1. The length of input arrayis a positive integer...

27 Remove Element

2018-08-29
阅读 2 分钟
1.3k
Given an array nums and a value val, remove all instances of thatvalue in-place and return the new length.Do not allocate extra space for another array, you must do this bymodifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you l...

561. Array Partition I

2018-08-28
阅读 1 分钟
1.2k
{代码...} 思路 因为要在两个数中取最小的值, 所以应该尽量找相邻的两个数一组, 这样才不会浪费一个大的数值。所以将数组排序, 找到两个中间大的那一个 复杂度 时间O(nlogn) 排序的复杂度空间O(1) 代码 {代码...}

344 Reverse String

2018-08-28
阅读 2 分钟
1.4k
Write a function that takes a string as input and returns the stringreversed.Example 1: Input: "hello" Output: "olleh" Example 2: Input: "A man, a plan, a canal: Panama" Output: "amanaP :lanac a ,nalpa ,nam A"

Pascal's Triangle I&II

2018-08-27
阅读 2 分钟
1.2k
把三角分为三种情况, 第一个1是每一行都有的, 结尾的1是从第二行才开始有, 然后中间的数字是从第三行开始, 对于i位置的数字是他前一行的i位置和i-1位置数字的和

Spiral Matrix I & II

2018-08-25
阅读 3 分钟
1.6k
Given a matrix of m x n elements (m rows, n columns), return allelements of the matrix in spiral order.Example 1: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output:[1,2,3,6,9,8,7,4,5] Example 2: Input: [ [1, 2, 3, 4], [5, 6, 7, 8], [9,10,11,12] ] Output:[1,2,3,4,8,12,11,10,9,5,6,7]

498. Diagonal Traverse

2018-08-24
阅读 2 分钟
1.8k
Given a matrix of M x N elements (M rows, N columns), return allelements of the matrix in diagonal order as shown in the below image.Example: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,4,7,5,3,6,8,9] Explanation: Note: The total number of elements of the given matrix will not e...

66 Plus One

2018-08-23
阅读 1 分钟
1.5k
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 thehead of the list, and each element in the array contain a singledigit. You may assume the integer does not contain any leading zero, e...

747 Largest Number At Least Twice of Others

2018-08-22
阅读 1 分钟
1.2k
In a given integer array nums, there is always exactly one largestelement. Find whether the largest element in the array is at least twice asmuch as every other number in the array. If it is, return the index of the largest element, otherwise return-1. Note: nums will have a length in the range [...

724. Find Pivot Index

2018-08-21
阅读 1 分钟
1.3k
Given an array of integers nums, write a method that returns the"pivot" index of this array.