leetcode
记录Leetcode刷题
magic_jiayu
这个作者很懒,什么都没留下…
展开
-
Leetcode01. Two Sum
Leetcode01. Two SumGiven 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 m...原创 2020-01-20 20:42:15 · 122 阅读 · 0 评论 -
Leetcode02. Add Two Numbers Medium
求两个链表表示的数相加原创 2020-01-20 23:20:01 · 117 阅读 · 0 评论 -
Leetcode03. Longest Substring Without Repeating Characters
Leetcode03. Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters.Example 1:Input: "abcabcbb"Output: 3 Explanation:...原创 2020-01-21 02:38:42 · 72 阅读 · 0 评论 -
Leetcode05. Longest Palindromic Substring
Leetcode05. 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"...原创 2020-01-21 10:39:27 · 96 阅读 · 0 评论 -
Leetcode11. Container With Most Water
Leetcode11. 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...原创 2020-01-21 12:02:32 · 122 阅读 · 0 评论 -
Leetcode15. 3Sum
Leetcode15. 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.Note: The solution s...原创 2020-01-21 13:33:55 · 104 阅读 · 0 评论 -
Leetcode17. Letter Combinations of a Phone Number
Leetcode17. 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 l...原创 2020-01-21 18:03:08 · 164 阅读 · 0 评论 -
Leetcode19. Remove Nth Node From End of List
Leetcode19. 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.Aft...原创 2020-01-21 18:33:53 · 100 阅读 · 0 评论 -
Leetcode20. Valid Parentheses
Leetcode20. Valid ParenthesesGiven a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must b...原创 2020-01-21 21:44:22 · 121 阅读 · 0 评论 -
Leetcode21. Merge Two Sorted Lists
Leetcode21. Merge Two Sorted ListsMerge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->...原创 2020-01-21 22:54:19 · 112 阅读 · 0 评论 -
Leetcode22. Generate Parentheses
Leetcode22. Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is[ "((()))", "...原创 2020-01-22 15:28:07 · 192 阅读 · 0 评论 -
Leetcode23. Merge k Sorted Lists
Leetcode23. Merge k Sorted ListsMerge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[ 1->4->5, 1->3->4, 2->6]Ou...原创 2020-01-23 19:05:45 · 114 阅读 · 0 评论 -
Leetcode31. Next Permutation
Leetcode31. Next PermutationImplement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrang...原创 2020-01-24 21:40:59 · 122 阅读 · 0 评论 -
Letcode33. Search in Rotated Sorted Array
Letcode33. Search in Rotated Sorted ArraySuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are g...原创 2020-01-29 22:37:32 · 80 阅读 · 0 评论 -
Leetcode34. Find First and Last Position of Element in Sorted Array
Given an array of integers nums sorted in ascending order, find thestarting and ending position of a given target valueYour algorithm’s runtime complexity must be in the order of O(log n).If the ta...原创 2020-01-30 08:55:50 · 100 阅读 · 0 评论 -
Leetcode46. Permutations
Leetcode46. PermutationsGiven 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]...原创 2020-02-04 14:27:56 · 136 阅读 · 0 评论 -
Leetcode48. Rotate Image
Leetcode48. Rotate ImageYou 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 modif...原创 2020-02-04 15:05:29 · 142 阅读 · 0 评论 -
Leetcode49. Group Anagrams
Leetcode49. Group AnagramsGiven an array of strings, group anagrams together.Note:All inputs will be in lowercase.The order of your output does not matter.Example:Input: ["eat", "tea", "tan"...原创 2020-02-04 23:44:40 · 259 阅读 · 0 评论 -
Leetcode53. Maximum Subarray
Leetcode53. Maximum SubarrayGiven 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,...原创 2020-02-05 09:30:41 · 128 阅读 · 0 评论 -
Leetcode55. Jump Game
Leetcode55. 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 posi...原创 2020-02-05 14:50:11 · 98 阅读 · 0 评论 -
Leetcode56. Merge Intervals
Leetcode56. 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 interva...原创 2020-02-05 15:15:35 · 130 阅读 · 0 评论 -
Leetcode62. Unique Paths
Leetcode62. 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 ...原创 2020-02-10 09:38:49 · 130 阅读 · 0 评论 -
Leetcode64. Minimum Path Sum
Leetcode64. 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 m...原创 2020-02-10 13:49:11 · 98 阅读 · 0 评论 -
Leetcode70. Climbing Stairs
Leetcode70. 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?Note:...原创 2020-02-10 14:32:54 · 214 阅读 · 0 评论 -
Leetcode75. Sort Colors
Leetcode75. 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.H...原创 2020-02-10 23:57:22 · 114 阅读 · 0 评论 -
Leetcode94. Binary Tree Inorder Traversal
Leetcode94. Binary Tree Inorder Traversal文章目录Leetcode94. Binary Tree Inorder Traversal解法一 经典递归解法二 基于栈的遍历解法三 Morris Traversal(利用线索二叉树)图解莫里斯方法C++解法Given a binary tree, return the inorder traversal of...原创 2020-02-11 18:50:53 · 252 阅读 · 0 评论 -
Leetcode96. Unique Binary Search Trees
Leetcode96. Unique Binary Search TreesGiven n, how many structurally unique BST’s (binary search trees) that store values 1 … n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a to...原创 2020-02-11 19:54:30 · 86 阅读 · 0 评论 -
Leetcode78. Subsets
Leetcode78. 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]Out...原创 2020-02-11 22:32:22 · 127 阅读 · 0 评论 -
Leetcode98. Validate Binary Search Tree
Leetcode98. Validate Binary Search Tree文章目录Leetcode98. Validate Binary Search Tree解法一 判断根节点是否合法解法二 判断左右孩子是否合法解法三 DFS BFS解法四 中序遍历Given a binary tree, determine if it is a valid binary search tree (B...原创 2020-02-12 10:52:15 · 170 阅读 · 0 评论 -
Leetcode101. Symmetric Tree
Leetcode101. Symmetric TreeGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ ...原创 2020-02-12 14:05:22 · 118 阅读 · 0 评论 -
Leetcode102. Binary Tree Level Order Traversal
Leetcode102. 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...原创 2020-02-12 16:28:42 · 137 阅读 · 0 评论 -
Leetcode104. Maximum Depth of Binary Tree
Leetcode104. 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 nod...原创 2020-02-12 18:51:16 · 146 阅读 · 0 评论 -
Leetcode105. Construct Binary Tree from Preorder and Inorder Traversal
Leetcode105. Construct Binary Tree from Preorder and Inorder TraversalGiven preorder and inorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in...原创 2020-02-13 19:37:09 · 181 阅读 · 0 评论 -
Leetcode114. Flatten Binary Tree to Linked List
Leetcode114. Flatten Binary Tree to Linked ListGiven a binary tree, flatten it to a linked list in-place. Forexample, given the following tree: 1 / \ 2 5 / \ \3 4 6The flatte...原创 2020-02-13 20:05:18 · 110 阅读 · 0 评论 -
Leetcode121. Best Time to Buy and Sell Stock
Leetcode121. 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....原创 2020-02-13 20:35:10 · 134 阅读 · 1 评论 -
Leetcode136. Single Number
Leetcode136. Single NumberGiven a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could ...原创 2020-02-13 20:51:00 · 118 阅读 · 0 评论 -
Leetcode139. Word Break
给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。拆分时可以重复使用字典中的单词。你可以假设字典中没有重复的单词。原创 2020-02-14 19:37:17 · 152 阅读 · 0 评论 -
Leetcode141. Linked List Cycle
判断链表是否为环原创 2020-02-14 19:56:53 · 122 阅读 · 0 评论 -
Leetcode142. Linked List Cycle II
判断链表是否有环,并把环的入口点找到原创 2020-02-14 21:14:32 · 153 阅读 · 0 评论 -
Leetcode146. LRU Cache
LRU 缓存。存储空间有限,当存满的时候的一种淘汰策略。LRU 选择删除最远一次操作过的元素,操作包括get 或者 put原创 2020-02-15 16:08:17 · 109 阅读 · 0 评论