
LeetCode
心血来潮,刷刷题
临渊行
不必仰望别人,自己亦是风景
展开
-
216. 组合总和 III(每日一题)
1、题目找出所有相加之和为 n 的 k 个数的组合。组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字。说明: 所有数字都是正整数。 解集不能包含重复的组合。示例 1:输入: k = 3, n = 7输出: [[1,2,4]]示例 2:输入: k = 3, n = 9输出: [[1,2,6], [1,3,5], [2,3,4]]来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/comb...原创 2020-09-11 09:49:19 · 534 阅读 · 0 评论 -
40. 组合总和 II(每日一题)
1、题目给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。candidates 中的每个数字在每个组合中只能使用一次。说明: 所有数字(包括目标数)都是正整数。 解集不能包含重复的组合。示例 1:输入: candidates = [10,1,2,7,6,1,5], target = 8,所求解集为:[ [1, 7], [1, 2, 5], [2, 6], [1, ...原创 2020-09-10 09:51:14 · 303 阅读 · 0 评论 -
39. 组合总和(每日一题)
1、题目给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。candidates 中的数字可以无限制重复被选取。说明: 所有数字(包括 target)都是正整数。 解集不能包含重复的组合。示例 1:输入:candidates = [2,3,6,7], target = 7,所求解集为:[ [7], [2,2,3]]示例 2:输入:candidates ...原创 2020-09-09 10:09:25 · 327 阅读 · 0 评论 -
77. 组合(每日一题)
1、题目给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合。示例:输入: n = 4, k = 2输出:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/combinations著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。2、思路:既可以使用动态规划,也可以用D...原创 2020-09-08 10:19:08 · 177 阅读 · 0 评论 -
60. 第k个排列(每日一题)
1、题目给出集合 [1,2,3,…,n],其所有元素共有 n! 种排列。按大小顺序列出所有排列情况,并一一标记,当 n = 3 时, 所有排列如下: "123" "132" "213" "231" "312" "321"给定 n 和 k,返回第 k 个排列。说明: 给定 n 的范围是 [1, 9]。 给定 k 的范围是[1, n!]。示例 1:输入: n = 3, k = 3输出: "213"示例 2:输...原创 2020-09-05 15:48:01 · 341 阅读 · 0 评论 -
LeetCode-066: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 el...原创 2019-02-09 09:58:04 · 184 阅读 · 0 评论 -
LeetCode-047:Permutations II
题目:Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[ [1,1,2], [1,2,1], [2,1,1]]题意:给出数组元素(有重复元素)的全...原创 2019-02-06 10:11:24 · 133 阅读 · 0 评论 -
LeetCode-035: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 arr...原创 2019-01-29 17:32:09 · 161 阅读 · 0 评论 -
LeetCode-040:Combination Sum II
题目:Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.Each number in candidate...原创 2019-02-05 14:48:22 · 215 阅读 · 0 评论 -
LeetCode-039:Combination Sum
题目:Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.The same r...原创 2019-02-04 07:55:30 · 140 阅读 · 0 评论 -
LeetCode-049:Group Anagrams
题目:Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat&原创 2019-02-03 13:13:23 · 167 阅读 · 0 评论 -
LeetCode-048:Rotate Image
题目: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 image in-place, which means you have to modify the input 2D mat...原创 2019-02-02 14:45:59 · 142 阅读 · 0 评论 -
LeetCode-042:Trapping Rain Water
题目:Given 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 ...原创 2019-02-07 23:32:55 · 130 阅读 · 0 评论 -
LeetCode-038:Count and Say
题目:The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 is read...原创 2019-01-30 12:16:58 · 143 阅读 · 0 评论 -
LeetCode-078:Subsets
题目:Given 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],...原创 2019-02-15 20:55:23 · 212 阅读 · 0 评论 -
LeetCode-058:Length of Last Word
题目:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is ...原创 2019-02-08 21:51:06 · 127 阅读 · 0 评论 -
LeetCode-067:Add Binary
题目:Given two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0.Example 1:Input: a = "11", b = "1"Output: "100"...原创 2019-02-10 09:31:04 · 189 阅读 · 0 评论 -
LeetCode-070:Climbing Stairs
题目:You 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?Note: Given n will be a pos...原创 2019-02-11 23:38:42 · 128 阅读 · 0 评论 -
LeetCode-069:Sqrt(x)
题目:Implement int sqrt(int x).Compute and return the square root of x, where x is guaranteed to be a non-negative integer.Since the return type is an integer, the decimal digits are truncated and...原创 2019-02-12 10:16:35 · 191 阅读 · 0 评论 -
LeetCode-083:Remove Duplicates from Sorted List
题目:Given a sorted linked list, delete all duplicates such that each element appear only once.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Outpu...原创 2019-02-13 16:46:56 · 117 阅读 · 2 评论 -
LeetCode-062:Unique Paths
题目: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 down or right at any point in time. The robot is trying to reach t...原创 2019-02-14 08:59:10 · 140 阅读 · 0 评论 -
LeetCode-028:Implement strStr()
题目:Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Ex...原创 2019-01-28 13:13:27 · 135 阅读 · 0 评论 -
LeetCode-053: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: 6Expl...原创 2019-02-01 14:45:07 · 172 阅读 · 0 评论 -
LeetCode-027: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...原创 2019-01-27 10:53:47 · 115 阅读 · 0 评论 -
LeetCode-002:Add Two Numbers
题目:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and ret...原创 2019-01-08 14:39:16 · 102 阅读 · 0 评论 -
LeetCode-014:Longest Common Prefix
题目:Write 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"]Ou...原创 2019-01-18 20:03:33 · 107 阅读 · 0 评论 -
LeetCode-017:Letter Combinations of a Phone Number
题目:Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) i...原创 2019-01-23 18:36:04 · 156 阅读 · 0 评论 -
LeetCode-008:String to Integer (atoi)
题目:Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting fro...原创 2019-01-13 14:09:24 · 142 阅读 · 0 评论 -
LeetCode-001:Two Sum
题目:Given 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 the ...原创 2019-01-07 22:11:19 · 113 阅读 · 0 评论 -
LeetCode-013:Roman to Integer
题目:Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-01-18 11:00:59 · 250 阅读 · 0 评论 -
LeetCode-009:Palindrome Number
题目:Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 121Output: trueExample 2:Input: -121Output: false...原创 2019-01-12 21:20:06 · 228 阅读 · 0 评论 -
LeetCode-012:Integer to Roman
题目:Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-01-17 19:46:22 · 140 阅读 · 0 评论 -
LeetCode-007: Reverse Integer
题目:Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we ar...原创 2019-01-11 17:10:21 · 149 阅读 · 0 评论 -
LeetCode-022:Generate Parentheses
题目:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()...原创 2019-01-24 12:06:27 · 167 阅读 · 0 评论 -
LeetCode-004:Median of Two Sorted Arrays
题目:There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).You may assume nums1 ...原创 2019-01-14 15:29:14 · 96 阅读 · 0 评论 -
LeetCode-019:Remove Nth Node From End of List
题目:Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the e...原创 2019-01-22 11:23:59 · 166 阅读 · 0 评论 -
LeetCode-011:Container With Most Water
题目: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). Fin...原创 2019-01-16 14:36:17 · 148 阅读 · 0 评论 -
LeetCode-026: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 mo...原创 2019-01-26 18:13:15 · 148 阅读 · 0 评论 -
LeetCode-046:Permutations
题目:Given a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]题意:给出数组的全排列...原创 2019-01-31 12:49:30 · 512 阅读 · 0 评论 -
LeetCode-020:Valid Parentheses
题目:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type...原创 2019-01-21 11:27:16 · 177 阅读 · 0 评论