
LeetCode
XP-Code
这个作者很懒,什么都没留下…
展开
-
LeetCode:215. Kth Largest Element in an Array
LeetCode:215. Kth Largest Element in an ArrayFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example 1:...原创 2019-07-23 15:07:36 · 147 阅读 · 0 评论 -
LeetCode:104. Maximum Depth of Binary Tree
LeetCode:104. Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf no...原创 2019-07-03 18:19:00 · 127 阅读 · 0 评论 -
LeetCode:617. Merge Two Binary Trees
LeetCode:617. Merge Two Binary TreesGiven two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need...原创 2019-07-03 15:49:41 · 148 阅读 · 0 评论 -
LeetCode:771. Jewels and Stones
LeetCode:771. Jewels and StonesYou're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You ...原创 2019-07-03 13:19:50 · 147 阅读 · 0 评论 -
LeetCode:75. Sort Colors
LeetCode:75. Sort ColorsGiven an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue....原创 2019-07-03 11:58:56 · 214 阅读 · 0 评论 -
LeetCode:72. Edit Distance
LeetCode:72. Edit DistanceGiven two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert ...原创 2019-07-02 20:11:00 · 208 阅读 · 0 评论 -
LeetCode:3. Longest Substring Without Repeating Characters
LeetCode:3. Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters.题目的意思就是求解一个字符串的最长无重复字符的连续子串。思路一(暴力求解)直接暴力求解,依次遍历字符串...原创 2019-06-21 09:24:13 · 195 阅读 · 0 评论 -
LeetCode:5. Longest Palindromic Substring
LeetCode:5. Longest Palindromic SubstringGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"...原创 2019-06-21 09:24:21 · 229 阅读 · 0 评论 -
LeetCode:11. Container With Most Water
LeetCode: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 li...原创 2019-06-21 09:24:28 · 168 阅读 · 0 评论 -
LeetCode:6.. ZigZag Conversion
LeetCode:6… ZigZag ConversionThe string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibilit...原创 2019-06-21 09:24:38 · 233 阅读 · 0 评论 -
LeetCode:12. Integer to Roman
LeetCode:12. Integer to RomanRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.意思就是用罗马数字表示一个整数,此外另外还有几个规则:I can be placed before V (5) and X (10) to make 4 and 9....原创 2019-06-21 09:24:49 · 170 阅读 · 0 评论 -
LeetCode:17. Letter Combinations of a Phone Number
LeetCode:17. Letter Combinations of a Phone NumberGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to ...原创 2019-06-21 09:25:02 · 172 阅读 · 0 评论 -
LeetCode:15. 3Sum
LeetCode:15. 3SumGiven an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Example:Given arr...原创 2019-06-21 09:25:19 · 119 阅读 · 0 评论 -
LeetCode:226. Invert Binary Tree
LeetCode:226. Invert Binary TreeInvert a binary tree.Example:Input: 4 / \ 2 7 / \ / \1 3 6 9Output: 4 / \ 7 2 / \ / \9 6 3 1翻转二叉树思路:递归翻转左右子树...原创 2019-07-03 21:14:22 · 155 阅读 · 0 评论 -
LeetCode:206. Reverse Linked List
LeetCode:206. Reverse Linked ListReverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULL翻转链表。思路一:头插法遍历链表,直接将元素插入到头部前面,最后链表就翻转...原创 2019-07-03 21:57:28 · 182 阅读 · 0 评论 -
LeetCode:102. Binary Tree Level Order Traversal
LeetCode:102. Binary Tree Level Order TraversalGiven a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3...原创 2019-07-23 15:03:07 · 132 阅读 · 0 评论 -
LeetCod:494. Target Sum
LeetCod:494. Target SumYou are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its n...原创 2019-07-29 21:40:02 · 164 阅读 · 0 评论 -
LeetCode:621. Task Scheduler
LeetCode:621. Task SchedulerGiven a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks. Tasks could be done without ori...原创 2019-07-30 21:42:21 · 167 阅读 · 0 评论 -
LeetCode:287. Find the Duplicate Number
LeetCode:287. Find the Duplicate NumberGiven an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume tha...原创 2019-07-19 19:50:37 · 156 阅读 · 0 评论 -
LeetCode:94. Binary Tree Inorder Traversal
LeetCode:94. Binary Tree Inorder TraversalGiven a binary tree, return the inorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,3,2]Follow u...原创 2019-07-17 16:28:42 · 190 阅读 · 0 评论 -
LeetCode:78. Subsets
LeetCode: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]O...原创 2019-07-19 15:26:52 · 156 阅读 · 0 评论 -
LeetCode:647. Palindromic Substrings
LeetCode:647. Palindromic SubstringsTHE END.原创 2019-07-17 10:28:59 · 210 阅读 · 0 评论 -
LeetCode:347. Top K Frequent Elements
LeetCode: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 = ...原创 2019-07-18 20:50:03 · 253 阅读 · 0 评论 -
LeetCode:238. Product of Array Except Self
LeetCode:238. Product of Array Except SelfGiven an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums...原创 2019-07-18 19:53:49 · 153 阅读 · 0 评论 -
LeetCode:739. Daily Temperatures
LeetCode:739. Daily TemperaturesGiven a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If...原创 2019-07-05 15:06:23 · 254 阅读 · 0 评论 -
LeetCode:406. Queue Reconstruction by Height
LeetCode:406. Queue Reconstruction by HeightSuppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person an...原创 2019-07-10 13:15:27 · 144 阅读 · 0 评论 -
LeetCode:338. Counting Bits
LeetCode:338. Counting BitsGiven a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array...原创 2019-07-05 08:22:50 · 142 阅读 · 0 评论 -
LeetCode:16. 3Sum Closest
LeetCode:16. 3Sum ClosestGiven an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may ass...原创 2019-06-21 09:25:26 · 123 阅读 · 0 评论 -
LeetCode:19. Remove Nth Node From End of List
LeetCode:19. Remove Nth Node From End of ListGiven 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.A...原创 2019-06-21 09:26:36 · 159 阅读 · 0 评论 -
LeetCode:24. Swap Nodes in Pairs
LeetCode:24. Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list's nodes, only nodes itself may be changed.Example:...原创 2019-06-21 09:25:32 · 136 阅读 · 0 评论 -
LeetCode:10. Regular Expression Matching
LeetCode:10. Regular Expression MatchingGiven an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches...原创 2019-06-19 20:24:16 · 154 阅读 · 0 评论 -
LeetCode:55. Jump Game
LeetCode:55. Jump GameGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that pos...原创 2019-06-19 18:12:41 · 172 阅读 · 0 评论 -
LeetCode:56. Merge Intervals
LeetCode:56. Merge IntervalsGiven a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since interv...原创 2019-06-19 18:07:47 · 160 阅读 · 0 评论 -
LeetCode:64. Minimum Path Sum
LeetCode: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 ...原创 2019-06-19 17:41:10 · 121 阅读 · 0 评论 -
LeetCode:62. Unique Paths
LeetCode:62. Unique PathsA 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...原创 2019-06-19 16:19:38 · 116 阅读 · 0 评论 -
LeetCode:382 Linked List Random Node
382. Linked List Random Node Given a singly linked list, return a random node’s value from the linked list. Each node must have the same probability of being chosen.原创 2016-08-11 09:45:23 · 935 阅读 · 0 评论 -
LeetCode:383 Ransom Note
383. Ransom Note>Given an arbitrary ransom note string and another string containing letters from all the magazines原创 2016-08-11 20:54:51 · 2789 阅读 · 0 评论 -
LeetCode:384 Shuffle an Array
384. Shuffle an Array Shuffle a set of numbers without duplicates.洗牌算法,题目的意思就是交换数组元素的位置,并且保证每种情况出现的概率是一样大。一开始的思路呢,就是生成一个随机数(0到数组长度之间),把这个随机数对应位置元素插入到一个等长的新数组中,如果生成的随机数已经出现过,则继续生成。直到新的数组放满。原创 2016-08-12 21:59:37 · 395 阅读 · 0 评论 -
LeetCode:381 Insert Delete GetRandom O(1)
381. Insert Delete GetRandom O(1) - Duplicates allowed Design a data structure that supports all following operations in average O(1) time. Note: Duplicate elements are allowed.原创 2016-08-13 12:30:23 · 1064 阅读 · 0 评论 -
LeetCode:378 Kth Smallest Element in a Sorted Matrix
378. Kth Smallest Element in a Sorted MatrixGiven a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.原创 2016-08-13 23:33:42 · 485 阅读 · 0 评论