
leetcode
文章平均质量分 90
leetcode刷题文档
yuSnwang
这个作者很懒,什么都没留下…
展开
-
120. Triangle
120. TriangleGiven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[[2],[3,4],[6,5,7],[4,1,8,3]]The minimum path sum from top to bottom原创 2020-09-25 11:39:18 · 89 阅读 · 0 评论 -
200. Number of Islands
200. Number of IslandsGiven a 2d grid map of '1’s (land) and '0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are a原创 2020-09-24 21:46:08 · 167 阅读 · 0 评论 -
64. Minimum Path Sum
64. Minimum Path SumGiven 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 numbers along its path.Note: You can only move either down or right at any point in time.Example:Input:[原创 2020-09-23 18:34:30 · 132 阅读 · 0 评论 -
78. Subsets
78. SubsetsGiven a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[[3],[1],[2],[1,2,3],[1,3],[2,3],[1,2],[]]来源:力扣(Lee原创 2020-09-20 10:15:51 · 133 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock
121. Best Time to Buy and Sell StockSay 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), design an algorithm原创 2020-09-17 23:21:51 · 155 阅读 · 0 评论 -
11. Container With Most Water
11. Container With Most WaterGiven 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原创 2020-09-17 12:23:41 · 100 阅读 · 0 评论 -
14. Longest Common Prefix
14. Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string “”.Example 1:Input: [“flower”,“flow”,“flight”]Output: “fl”Example 2:Input: [“dog”,“ra原创 2020-09-16 14:48:35 · 123 阅读 · 0 评论 -
22. Generate Parentheses
22. Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For examplegiven n = 3, a solution set is:[“((()))”,“(()())”,“(())()”,“()(())”,“()()()”]来源:力扣(LeetCode)链接:https://lee原创 2020-09-15 16:17:53 · 145 阅读 · 0 评论 -
70. Climbing Stairs
70. Climbing StairsYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Example 1:Input: 2Output: 2Explanation: There are two ways to climb原创 2020-09-14 12:28:44 · 154 阅读 · 0 评论 -
42. Trapping Rain Water
42. Trapping Rain WaterGiven n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In th原创 2020-09-11 17:40:03 · 163 阅读 · 0 评论 -
496. Next Greater Element I
496. Next Greater Element IYou are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1’s elements in the corresponding places of nums2.The Next Greater Number of a原创 2020-09-11 16:21:25 · 138 阅读 · 0 评论 -
29. Divide Two Integers
29. Divide Two IntegersGiven two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividing dividend by divisor.The integer division should truncate toward zero, which me原创 2020-09-10 16:07:30 · 133 阅读 · 0 评论 -
31. Next Permutation
31. Next PermutationImplement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order)原创 2020-09-09 21:21:06 · 120 阅读 · 0 评论 -
1370. Increasing Decreasing String
1370. Increasing Decreasing StringGiven a string s. You should re-order the string using the following algorithm:Pick the smallest character from s and append it to the result.Pick the smallest character from s which is greater than the last appended ch原创 2020-09-08 16:00:50 · 123 阅读 · 0 评论 -
347. Top K Frequent Elements
347. Top K Frequent ElementsGiven a non-empty array of integers, return the k most frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Output: [1]Note:You may assume k is always valid, 1 ≤ k原创 2020-09-07 19:19:36 · 317 阅读 · 0 评论 -
179. Largest Number
179. Largest NumberGiven a list of non negative integers, arrange them such that they form the largest number.Example 1:Input: [10,2]Output: “210”Example 2:Input: [3,30,34,5,9]Output: “9534330”Note: The result may be very large, so you need to retu原创 2020-09-05 11:08:21 · 112 阅读 · 0 评论 -
365. Water and Jug Problem
365. Water and Jug ProblemYou are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these two jugs.If z liters of water is原创 2020-09-04 21:17:15 · 163 阅读 · 0 评论 -
leetcode1030. Matrix Cells in Distance Order
leetcode1030. Matrix Cells in Distance OrderWe are given a matrix with R rows and C columns has cells with integer coordinates (r, c), where 0 <= r < R and 0 <= c < C.Additionally, we are given a cell in that matrix with coordinates (r0, c0).原创 2020-09-04 11:23:42 · 149 阅读 · 0 评论 -
973. K Closest Points to Origin
973. K Closest Points to OriginWe have a list of points on the plane. Find the K closest points to the origin (0, 0).(Here, the distance between two points on a plane is the Euclidean distance.)You may return the answer in any order. The answer is gua原创 2020-09-02 16:38:40 · 144 阅读 · 0 评论 -
leetcode242 Anagram
leetcode242 AnagramGiven two strings s and t, write a function to determine if t is an alphabetic word of s.给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/valid-anagram著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。Exam原创 2020-09-01 16:34:33 · 124 阅读 · 0 评论 -
leetcode56 intervals merge
leetcode56 intervals merge给出一个区间的集合,请合并所有重叠的区间。Given a set of intervals, merge all overlapped intervals.Examples:Input:intervals = [[1,3],[2,6],[8,10],[15,18]]Output:[[1,6],[8,10],[15,18]]Input:intervals = [[1,4],[4,5]]Output[[1,5]]来源:力扣(LeetCo原创 2020-08-31 17:08:23 · 127 阅读 · 0 评论 -
leetcode350 两个数组的交集 II
leetcode350 两个数组的交集 II给定两个数组,编写一个函数来计算它们的交集。示例1输入:nums1 = [1,2,2,1], nums2 = [2,2]输出:[2,2]示例 2:输入:nums1 = [4,9,5], nums2 = [9,4,9,8,4]输出:[4,9]说明:输出结果中每个元素出现的次数,应与元素在两个数组中出现次数的最小值一致。我们可以不考虑输出结果的顺序。进阶:如果给定的数组已经排好序呢?你将如何优化你的算法?来源:力扣(LeetCode)链接:h原创 2020-08-29 10:55:31 · 110 阅读 · 0 评论 -
leetcode969 煎饼排序
leetcode 969 煎饼排序给定数组 A,我们可以对其进行煎饼翻转:我们选择一些正整数 k<=A.length,然后反转 A 的前 k 个元素的顺序。我们要执行零次或多次煎饼翻转(按顺序一次接一次地进行)以完成对数组 A 的排序。返回能使 A 排序的煎饼翻转操作所对应的 k 值序列。任何将数组排序且翻转次数在 10 * A.length 范围内的有效答案都将被判断为正确。示例:输入:[3,2,4,1]输出:[4,2,4,3]解释:我们执行 4 次煎饼翻转,k 值分别为 4,2,4,原创 2020-08-28 10:17:26 · 227 阅读 · 0 评论 -
leetcode164 最大间距
164 最大间距给定一个无序的数组,找出数组在排序之后,相邻元素之间最大的差值。如果数组元素个数小于 2,则返回 0。示例 1:输入: [3,6,9,1]输出: 3解释: 排序后的数组是 [1,3,6,9], 其中相邻元素 (3,6) 和 (6,9) 之间都存在最大差值 3。示例 2:输入: [10]输出: 0解释: 数组元素个数小于 2,因此返回 0。说明:你可以假设数组中所有元素都是非负整数,且数值在 32 位有符号整数范围内。请尝试在线性时间复杂度和空间复杂度的条件下解决此问题原创 2020-08-27 09:57:24 · 212 阅读 · 0 评论 -
leetcode17 电话号码的字母组合
leetcode17 电话号码的字母组合给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。示例输入:“23”输出:[“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”].说明:尽管上面的答案是按字典序排列的,但是你可以任意选择答案输出的顺序。答题思路:可以认为是广度优先的搜索思路,例如针对于“23”这样的输入:首先考虑2对应的三种情况即:a,b,c原创 2020-08-26 11:25:15 · 107 阅读 · 0 评论 -
leetcode75 颜色分类
75 颜色分类给定一个包含红色、白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。此题中,我们使用整数 0、 1 和 2 分别表示红色、白色和蓝色。注意:不能使用代码库中的排序函数来解决这道题。示例输入: [2,0,2,1,1,0]输出: [0,0,1,1,2,2]进阶:一个直观的解决方案是使用计数排序的两趟扫描算法。首先,迭代计算出0、1 和 2 元素的个数,然后按照0、1、2的排序,重写当前数组。你能想出一个仅使用常数空原创 2020-08-25 09:57:42 · 182 阅读 · 0 评论 -
leetcode 7整数反转
7 整数反转给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。示例1输入:123输出:321示例2输入-123输出-321示例3输入:120输出:21注意:假设我们的环境只能存储得下 32 位的有符号整数,则其数值范围为 [−231, 231 − 1]。请根据这个假设,如果反转后整数溢出那么就返回 0。解题思路:作为作者写的第一份Go语言的代码,选择了这样一道思路清晰,但比较注重概念的一题作为开端。正如官方文档所提及的,解题的关键点就在于判断是否**“溢出原创 2020-08-24 20:32:39 · 144 阅读 · 0 评论