leetcode 15 3Sum

2018-02-11
阅读 2 分钟
2.1k
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.给定一个整数数组s,我们要找出s中是否有三个不同元素的加和等于0,如果有,输出所有满足条件的序列。要求序列不重复。 For example, 输入数组S = [-1, ...

leetcode 9 Palindrome Number

2018-02-09
阅读 1 分钟
1.7k
Determine whether an integer is a palindrome. Do this without extra space.题目要求我们在不占用额外空间的前提下,判断一个整数是否是回文数。

leetcode 7 Reverse Integer

2018-02-08
阅读 1 分钟
1.9k
Given a 32-bit signed integer, reverse digits of an integer.题目要求我们给出一个数的翻转数 Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21

leetcode 11 Container With Most Water

2018-02-08
阅读 1 分钟
2.3k
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most wa...

leetcode 766 Toeplitz Matrix

2018-02-07
阅读 1 分钟
3.3k
matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.Now given an M x N matrix, return True if and only if the matrix is Toeplitz.如果一个矩阵的每一条斜对角线(左上到右下)上的元素都相等,则我们称它为托普利兹矩阵。现在输入一个M*N大小的矩阵,如果它是一个托普利兹...

leetcode 746 Min Cost Climbing Stairs

2018-02-06
阅读 1 分钟
2.5k
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1. 给定一个...

leetcode 724 Find Pivot Index

2018-02-06
阅读 2 分钟
3.8k
Given an array of integers nums, write a method that returns the "pivot" index of this array.We define the pivot index as the index where the sum of the numbers to the left of the index is equal to the sum of the numbers to the right of the index.If no such index exists, we should return -1. If t...

leetcode 697 Degree of an Array

2018-02-05
阅读 2 分钟
3k
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.

leetcode 695 Max Area of Island

2018-02-05
阅读 2 分钟
2.1k
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.Find the maximum area of an island in the given 2D array. (If there is no island, t...

leetcode 665 Non-decreasing Array

2018-02-05
阅读 1 分钟
2.5k
Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.We define an array is non-decreasing if array[i] <= array[i + 1] holds for every i (1 <= i < n). 给定一个整数数组,如果最多改变一个元素的值,就可使整个数组元素的值单调递...

leetcode 643 Maximum Average Subarray I

2018-02-03
阅读 1 分钟
2k
Given an array consisting of n integers, find the contiguous subarray of given length k that has the maximum average value. And you need to output the maximum average value. 输入一个数组nums和一个整数k。要求找出输入数组中长度为k的子数组,并且要求子数组元素的加和平均值最大。返回这个最大的平均值。 ...

leetcode 628 Maximum Product of Three Numbers

2018-02-03
阅读 2 分钟
2.4k
Given an integer array, find three numbers whose product is maximum and output the maximum product.输入一个大小大于等于三的数组,给出其中任意三个数乘积中的最大乘积 Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24

leetcode 605 Can Place Flowers

2018-02-03
阅读 2 分钟
2.4k
Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.Given a flowerbed (represented as an array containing 0 and 1, where 0 means empty and 1 means not empt...

581 Shortest Unsorted Continuous Subarray

2018-02-02
阅读 1 分钟
2.7k
Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You need to find the shortest such subarray and output its length.题目的意思是输入一个数组,这个数组可能是排序好的,...

leetcode 566 Reshape the Matrix

2018-02-01
阅读 2 分钟
2k
You're given a matrix represented by a two-dimensional array, and two positive integers r and c representing the row number and column number of the wanted reshaped matrix, respectively.The reshaped matrix need to be filled with all the elements of the original matrix in the same row-traversing o...

leetcoed 532 K-diff Pairs in an Array

2018-02-01
阅读 2 分钟
1.6k
Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers in the array and their absolute difference is k.这道题的意思是,输入一个整数数组和一个整数k,我们需...

leetcode 448 Find All Numbers Disappeared in an Array

2018-01-31
阅读 1 分钟
1.7k
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count ...

leetcode 414 Third Maximum Number

2018-01-31
阅读 1 分钟
1.7k
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).如果不存在第三大的数,则返回最大的数。

leetcode 283 Move Zeroes

2018-01-31
阅读 1 分钟
1.6k
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.For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0].这道题的意思就是将一个数组里面的所有0移到数组的最后,同时要...

leetcode 268 Missing Number

2018-01-30
阅读 1 分钟
1.6k
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. 题目的意思是输入一个长度为n的数组,找到0~n这n+1个数字中不存在于数组中的“丢失的数字” Example 1:Input: [3,0,1] Output: 2Example 2:Input: [9,6,4,2,3,5,7,0,1] Output: 8

leetcode 219 Contains Duplicate II

2018-01-30
阅读 1 分钟
2.8k
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,如果数组中存在相等的两个数,而且他们的位置差不超过...

leetcode 169 Majority Element

2018-01-29
阅读 2 分钟
1.4k
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 always exist in the array.输入一个大小为n的数组,整个数组里面将会含有一个众数,即这个元素出现的次数大于...

leetcode 217 Contains Duplicate

2018-01-29
阅读 2 分钟
1.6k
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. 输入一个整数的数组,如果数组中的元素有重复的,那么返回true,如果数组中的元素都是唯一的...

leetcode 167 Two Sum II - Input array is sorted

2018-01-18
阅读 2 分钟
2.1k
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 such that they add up to the target, where index1 must be less than index2. Please note that your r...

leetcode 121 Best Time to Buy and Sell Stock

2018-01-15
阅读 1 分钟
2.3k
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 (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Leetcode 118&119 Pascal's Triangle

2018-01-14
阅读 2 分钟
2.1k
For example, given numRows = 5,Return [1], [1,1], [1,2,1],[1,3,3,1],[1,4,6,4,1]

leetcode 88 Merge Sorted Array

2018-01-11
阅读 1 分钟
1.5k
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.

leetcode_53 Maximum Subarray

2018-01-09
阅读 1 分钟
1.4k
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] has the largest sum = 6.

Leetcode 27 Remove Element

2018-01-07
阅读 1 分钟
1.3k
要求输入:给定数组nums[],数字val要求输出:数组中不等于val的元素个数n,同时要求不等于数字val的n个元素放置在数组的前n个位置(不要求顺序)

leetcode_67 Add Binary

2017-05-24
阅读 2 分钟
2k
Given two binary strings, return their sum (also a binary string).For example,a = "11",b = "1",Return "100".