Leetcode_Array
文章平均质量分 79
想当厨子的程序媛
前期追深度,否则会华而不实,后期追广度,否则会坐井观天;
展开
-
LeetCode——118. Pascal's Triangle
题目原址https://leetcode.com/problems/pascals-triangle/description/题目描述Given numRows, generate the first numRows of Pascal’s triangle. For example, given numRows = 5, Return 解题思路帕斯卡三角(杨辉三...原创 2018-02-08 20:44:55 · 200 阅读 · 0 评论 -
Leetcode——40. Combination Sum II【dfs重要】
题目原址https://leetcode.com/problems/combination-sum-ii/description/题目描述Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidat...原创 2018-05-22 10:44:32 · 147 阅读 · 0 评论 -
Leetcode——63. Unique Paths II
题目原址https://leetcode.com/problems/unique-paths-ii/description/题目描述A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move eith...原创 2018-05-15 15:30:43 · 138 阅读 · 0 评论 -
Leetcode——238. Product of Array Except Self
题目原址https://leetcode.com/problems/product-of-array-except-self/description/题目描述Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the produ...原创 2018-05-08 18:50:38 · 118 阅读 · 0 评论 -
Leetcode——64. Minimum Path Sum
题目原址https://leetcode.com/problems/minimum-path-sum/description/题目描述Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all...原创 2018-05-15 14:44:01 · 184 阅读 · 0 评论 -
Leetcode——45. Jump Game II
题目原址https://leetcode.com/problems/jump-game-ii/description/题目描述Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array r...原创 2018-05-15 14:05:38 · 138 阅读 · 0 评论 -
Leetcode——55. Jump Game
题目原址解题思路给定一个数组,数组的下标表示你当前所在的位置,数组中的元素值表示你一次可以最大跳跃的步数,现在假设你在0位置上,判断是否可以跳到最末尾的位置。使用贪心算法解决该题。使用两个指针temp和maxReach ,temp用来表示当前位置,maxReach用来表示下一步能够到达的最远位置。在每次的遍历中都更新maxReach的值,以确保maxReach的值为每次遍历的最大值...原创 2018-05-15 13:43:45 · 134 阅读 · 0 评论 -
Leetcode—— 54. Spiral Matrix
题目原址https://leetcode.com/problems/spiral-matrix/description/题目描述Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. Example 1: Input: ...原创 2018-05-15 13:20:24 · 98 阅读 · 0 评论 -
Leetcode——495. Teemo Attacking
题目原址https://leetcode.com/problems/teemo-attacking/description/题目描述In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the ...原创 2018-05-08 16:41:05 · 233 阅读 · 0 评论 -
Leetcode——57. Insert Interval
题目原址https://leetcode.com/problems/insert-interval/description/题目描述Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that ...原创 2018-05-22 13:54:33 · 123 阅读 · 0 评论 -
Leetcode——611. Valid Triangle Number
题目原址https://leetcode.com/problems/valid-triangle-number/description/题目描述Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array tha...原创 2018-05-16 10:57:44 · 399 阅读 · 0 评论 -
Leetcode——718. Maximum Length of Repeated Subarray(DP重要)
题目原址https://leetcode.com/problems/maximum-length-of-repeated-subarray/description/题目描述Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.E...原创 2018-05-23 12:47:16 · 248 阅读 · 0 评论 -
Leetcode——48. Rotate Image
题目原址https://leetcode.com/problems/rotate-image/description/题目描述You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the...原创 2018-05-23 10:28:14 · 184 阅读 · 0 评论 -
Leetcode——75. Sort Colors
题目原址https://leetcode.com/problems/sort-colors/description/题目描述Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with ...原创 2018-05-16 16:27:13 · 125 阅读 · 0 评论 -
Leetcode——228. Summary Ranges
题目原址https://leetcode.com/problems/summary-ranges/description/题目描述Given a sorted integer array without duplicates, return the summary of its ranges.Example1: Input: [0,1,2,4,5,7] Outp...原创 2018-05-16 15:52:13 · 108 阅读 · 0 评论 -
Leetcode——609. Find Duplicate File in System
题目原址https://leetcode.com/problems/find-duplicate-file-in-system/description/题目描述给定一个String类型的数组,数组中包含文件的根目录和文件名称,文件名称后面包含的是文件的内容,现在要求将内容相同的文件目录放在一个List中,将多个包含不同内容的List放入一个List<List<>>...原创 2018-05-22 20:46:05 · 328 阅读 · 0 评论 -
Leetcode——209. Minimum Size Subarray Sum
题目原址https://leetcode.com/problems/minimum-size-subarray-sum/description/题目描述Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of ...原创 2018-05-16 12:51:10 · 144 阅读 · 0 评论 -
Leetcode——153. Find Minimum in Rotated Sorted Array
题目原址https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/题目描述Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [...原创 2018-05-16 12:04:47 · 152 阅读 · 0 评论 -
Leetcode——152. Maximum Product Subarray
题目原址https://leetcode.com/problems/maximum-product-subarray/description/题目描述Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has ...原创 2018-05-16 11:39:55 · 176 阅读 · 0 评论 -
Leetcode ——16. 3Sum Closest
解题思路这个题于15题类似,15题是要找到三个数相加等于0,这个题是要找到最接近目标 三的个数之和首先要对数组进行排序,然后采用三个指针的形式对数组进行查找,通过两层for循环,一层for循环,将三个指针变为2个指针。最后可以比较两个指针所指向位置的元素和于目标的和进行比较即可AC代码class Solution { public int threeSumClosest(...原创 2018-05-14 16:40:11 · 172 阅读 · 0 评论 -
Leetcode——11. Container With Most Water
题目原址https://leetcode.com/problems/container-with-most-water/description/题目描述Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines a...原创 2018-05-14 14:33:46 · 149 阅读 · 0 评论 -
Leetcode——565. Array Nesting
题目原址https://leetcode.com/problems/array-nesting/description/题目描述A zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] ...原创 2018-05-09 10:12:24 · 216 阅读 · 0 评论 -
Leetcode——724. Find Pivot Index
题目原址https://leetcode.com/problems/find-pivot-index/description/题目描述Given an array of integers nums, write a method that returns the “pivot” index of this array. We define the pivot index as th原创 2018-02-07 15:49:10 · 245 阅读 · 0 评论 -
Leetcode——121. Best Time to Buy and Sell Stock
题目原址https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/题目描述Say you have an array for which the ith element is the price of a given stock on day i. If you were only perm原创 2018-02-07 15:17:28 · 186 阅读 · 0 评论 -
Leetcode——268. Missing Number
题目原址https://leetcode.com/problems/missing-number/description/题目描述Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.Example1原创 2018-02-07 14:24:01 · 175 阅读 · 0 评论 -
Leetcode—— 283 141 628. Maximum Product of Three Numbers
题目原址https://leetcode.com/problems/maximum-product-of-three-numbers/description/题目描述Given an integer array, find three numbers whose product is maximum and output the maximum product.Example原创 2018-02-07 13:44:56 · 137 阅读 · 0 评论 -
Leetcode——697. Degree of an Array
题目原址https://leetcode.com/problems/degree-of-an-array/description/题目描述Example1: Input: [1, 2, 2, 3, 1] Output: 2 Explanation: The input array has a degree of 2 because both elements原创 2018-02-07 13:11:47 · 231 阅读 · 0 评论 -
Leetcode——532. K-diff Pairs in an Array
题目原址https://leetcode.com/problems/k-diff-pairs-in-an-array/description/题目描述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 ...原创 2018-02-09 10:56:59 · 198 阅读 · 0 评论 -
Leetcode——643. Maximum Average Subarray I
题目原址https://leetcode.com/problems/maximum-average-subarray-i/description/题目描述Given an array consisting of n integers, find the contiguous subarray of given length k that has the maximum averag...原创 2018-02-08 21:17:21 · 167 阅读 · 0 评论 -
Leetcode——769. Max Chunks To Make Sorted
题目原址https://leetcode.com/problems/max-chunks-to-make-sorted/description/题目描述Given an array arr that is a permutation of [0, 1, ..., arr.length - 1], we split the array into some number of “chu...原创 2018-05-09 13:44:17 · 148 阅读 · 0 评论 -
Leetcode——825. Friends Of Appropriate Ages
题目原址https://leetcode.com/problems/friends-of-appropriate-ages/description/题目描述Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person. ...原创 2018-05-17 11:38:59 · 846 阅读 · 0 评论 -
Leetcode——39. Combination Sum
题目原址https://leetcode.com/problems/combination-sum/description/题目描述Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in...原创 2018-05-14 13:51:42 · 137 阅读 · 0 评论 -
Leetcode——216. Combination Sum III
题目原址https://leetcode.com/problems/combination-sum-iii/description/题目描述Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and...原创 2018-05-14 13:01:17 · 164 阅读 · 0 评论 -
Leetcode——62. Unique Paths
题目原址https://leetcode.com/problems/unique-paths/description/题目描述A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either ...原创 2018-05-12 19:22:44 · 125 阅读 · 0 评论 -
Leetcode——287. Find the Duplicate Number
题目原址https://leetcode.com/problems/find-the-duplicate-number/description/题目描述Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least...原创 2018-05-12 18:49:07 · 154 阅读 · 0 评论 -
Leetcode——78. Subsets
题目原址https://leetcode.com/problems/subsets/description/题目描述Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicat...原创 2018-05-12 18:18:01 · 107 阅读 · 0 评论 -
Leetcode——714. Best Time to Buy and Sell Stock with Transaction Fee
题目原址https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/description/题目描述给定一个数组和一个变量,其中数组中的元素表示当天的股票价格,变量表示每次交易需要支付的固定费用。不限制股票的购买和售出的次数,但是要求在购买新的股票之前要将手中的股票全部售出。...原创 2018-05-12 16:36:38 · 361 阅读 · 0 评论 -
Leetcode——338. Counting Bits
题目原址https://leetcode.com/problems/counting-bits/description/题目描述给定一个整数n,返回从1到n对应的数字的二进制上的1的个数,将结果存在数组中返回。 数字 二进制 与前面数的关系 二进制中1的个数 1 0001 1 2 0010 1 3 001...原创 2018-05-18 13:16:13 · 146 阅读 · 0 评论 -
Leetcode——162. Find Peak Element
题目原址https://leetcode.com/problems/find-peak-element/description/题目描述A peak element is an element that is greater than its neighbors. Given an input array nums, where nums[i] ≠ nums[i+1], find...原创 2018-05-18 13:06:24 · 145 阅读 · 0 评论 -
Leetcode——795. Number of Subarrays with Bounded Maximum
题目描述We are given an array A of positive integers, and two positive integers L and R (L <= R). Return the number of (contiguous, non-empty) subarrays such that the value of the maximum array elem...原创 2018-05-23 13:26:44 · 163 阅读 · 0 评论