LeetCode
文章平均质量分 83
木头不是哑巴
这个作者很懒,什么都没留下…
展开
-
516. Longest Palindromic Subsequence
516. Longest Palindromic SubsequenceGiven a strings, findthe longest palindromicsubsequence's length ins.Asubsequenceis a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaini...原创 2021-05-03 17:34:29 · 162 阅读 · 0 评论 -
337. House Robber III
337. House Robber IIIThe thief has found himself a new place for his thievery again. There is only one entrance to this area, calledroot.Besides theroot, each house has one and only one parent house. After a tour, the smart thief realized that all ho..原创 2021-04-23 23:10:34 · 128 阅读 · 0 评论 -
124. Binary Tree Maximum Path Sum
124.Binary Tree Maximum Path SumApathin a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequenceat most once. Note that the path does not need to pass t...原创 2021-04-23 00:04:53 · 152 阅读 · 0 评论 -
43. Multiply Strings
43.Multiply StringsGiven two non-negative integersnum1andnum2represented as strings, return the product ofnum1andnum2, also represented as a string.Note:You must not use any built-in BigInteger library or convert the inputs to integer directly...转载 2021-04-17 13:16:16 · 96 阅读 · 1 评论 -
316. Remove Duplicate Letters
316.Remove Duplicate LettersGiven a strings, remove duplicate letters so that every letter appears once and only once. You must make sure your result isthe smallest in lexicographical orderamong all possible results.Note:This question is the same ...原创 2021-04-17 11:50:34 · 89 阅读 · 0 评论 -
662. Maximum Width of Binary Tree
662.Maximum Width of Binary TreeGiven a binary tree, write a function to get the maximum width of the given tree. The maximum width of a tree is the maximum width among all levels.The width of one level is defined as the length between the end-nodes (.原创 2021-04-11 12:47:21 · 75 阅读 · 0 评论 -
1367. Linked List in Binary Tree
1367. Linked List in Binary TreeGiven a binary treerootand alinked list withheadas the first node.Return True if all the elements in the linked list starting from theheadcorrespond to somedownward pathconnected in the binary treeotherwise re...原创 2021-04-11 11:29:24 · 93 阅读 · 0 评论 -
979. Distribute Coins in Binary Tree
979.Distribute Coins in Binary TreeYou are given therootof a binary tree withnnodes where eachnodein the tree hasnode.valcoins and there arencoins total.In one move, we may choose two adjacent nodes and move one coin from one node to another...原创 2021-04-11 00:02:51 · 102 阅读 · 0 评论 -
297. Serialize and Deserialize Binary Tree
297. Serialize and Deserialize Binary Treeerialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructe原创 2021-04-10 18:57:42 · 78 阅读 · 0 评论 -
538. Convert BST to Greater Tree
538.Convert BST to Greater TreeGiven therootof a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.As a reminder, a...原创 2021-04-10 16:50:14 · 74 阅读 · 0 评论 -
652. Find Duplicate Subtrees
652.Find Duplicate SubtreesGiven therootof a binary tree, return allduplicate subtrees.For each kind of duplicate subtrees, you only need to return the root node of anyoneof them.Two trees areduplicateif they have thesame structurewith the...原创 2021-04-10 15:54:26 · 85 阅读 · 0 评论 -
23. Merge k Sorted Lists
23. Merge k Sorted ListsYou are given an array ofklinked-listslists, each linked-list is sorted in ascending order.Merge all the linked-lists into one sorted linked-list and return it.Example 1:Input: lists = [[1,4,5],[1,3,4],[2,6]]Output: ...原创 2021-04-09 00:07:13 · 101 阅读 · 0 评论 -
138. Copy List with Random Pointer
138.Copy List with Random PointerA linked list of lengthnis given such that each node contains an additional random pointer, which could point to any node in the list, ornull.Construct adeep copyof the list. The deep copy should consist of exactl...原创 2021-04-08 23:39:21 · 78 阅读 · 0 评论 -
148. Sort List
148.Sort ListGiven theheadof a linked list, returnthe list after sorting it inascending order.Follow up:Can you sort the linked list inO(n logn)time andO(1)memory (i.e. constant space)?Example 1:Input: head = [4,2,1,3]Output: [1,2,...原创 2021-04-08 23:18:45 · 163 阅读 · 0 评论 -
332. Reconstruct Itinerary
332.Reconstruct ItineraryGiven a list of airline tickets represented by pairs of departure and arrival airports[from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs fromJFK. Thus, the itinerary must begin with...转载 2020-08-08 00:28:56 · 141 阅读 · 0 评论 -
1530. Number of Good Leaf Nodes Pairs
1530. Number of Good Leaf Nodes PairsGiven therootof a binary tree and an integerdistance. A pair of two differentleafnodes of a binary tree is said to be good if the length ofthe shortest pathbetween them is less than or equal todistance.Retur...原创 2020-08-06 23:54:46 · 223 阅读 · 0 评论 -
132. Palindrome Partitioning II
132. Palindrome Partitioning II[LeetCode] Palindrome Partitioning II 拆分回文串之二Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs.Example:...转载 2020-07-18 22:46:01 · 125 阅读 · 0 评论 -
647. Palindromic Substrings
Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist ...转载 2020-04-21 00:23:36 · 137 阅读 · 0 评论 -
494. Target Sum
You 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 new symbol.Find out how m...转载 2020-04-19 23:54:25 · 122 阅读 · 0 评论 -
[LeetCode] 416. Partition Equal Subset Sum
Given anon-emptyarray containingonly positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note:Each of the array eleme...转载 2020-04-19 23:24:38 · 122 阅读 · 0 评论 -
139. Word Break
Given anon-emptystringsand a dictionarywordDictcontaining a list ofnon-emptywords, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.Note:The ...转载 2020-04-12 21:21:34 · 205 阅读 · 0 评论 -
LeetCode 滑动窗口(Sliding Window)类问题总结
导语滑动窗口类问题是面试当中的高频题,问题本身其实并不复杂,但是实现起来细节思考非常的多,想着想着可能因为变量变化,指针移动等等问题,导致程序反复删来改去,有思路,但是程序写不出是这类问题最大的障碍。本文会将 LeetCode 里面的大部分滑动窗口问题分析、总结、分类,并提供一个可以参考的模版,相信可以有效减少面试当中的算法实现部分的不确定性。题目概览滑动窗口这类问题一般需要用到双...转载 2020-03-22 15:08:08 · 270 阅读 · 0 评论 -
322. Coin Change
322. Coin ChangeYou are given coins of different denominations and a total amount of moneyamount. Write a function to compute the fewest number of coins that you need to make up that amount. If tha...转载 2020-03-08 18:38:06 · 109 阅读 · 0 评论 -
硬币面值组合问题
转自:https://www.cnblogs.com/python27/p/3303721.html问题描述 假设我们有8种不同面值的硬币{1,2,5,10,20,50,100,200},用这些硬币组合够成一个给定的数值n。例如n=200,那么一种可能的组合方式为 200 = 3 * 1 + 1*2 + 1*5 + 2*20 + 1 * 50 + 1 * 100. 问总过有多少种可能的组...转载 2020-03-08 16:11:32 · 1092 阅读 · 0 评论 -
LeetCode-DP算法 | 最长公共子序列和最长公共子串区别
转自:https://blog.csdn.net/u012426298/article/details/82796660最长公共子串(Longest Common Substring)与最长公共子序列(Longest Common Subsequence)的区别: 子串要求在原字符串中是连续的,而子序列则只需保持相对顺序一致,并不要求连续。例如X = {a, Q, 1, 1}; Y = {a,...转载 2020-03-08 13:55:33 · 307 阅读 · 0 评论 -
560. Subarray Sum Equals K
560. Subarray Sum Equals KGiven an array of integers and an integerk, you need to find the total number of continuous subarrays whose sum equals tok.Example 1:Input:nums = [1,1,1], k = 2Outp...原创 2020-03-08 00:27:01 · 125 阅读 · 0 评论 -
Leetcode 309. Best Time to Buy and Sell Stock with Cooldown
Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one ...原创 2020-01-15 00:05:07 · 118 阅读 · 0 评论 -
Leetcode 121. Best Time to Buy and Sell Stock I II
Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock),...原创 2020-01-12 21:48:31 · 141 阅读 · 0 评论 -
Leetcode 198. House Robber I II III
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house...原创 2020-01-12 09:11:44 · 219 阅读 · 0 评论 -
Leetcode 91. Decode Ways
A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given anon-emptystring containing only digits, determine t...原创 2020-01-11 18:06:36 · 161 阅读 · 0 评论 -
279. Perfect Squares
Given a positive integern, find the least number of perfect square numbers (for example,1, 4, 9, 16, ...) which sum ton.Example 1:Input: n = 12Output: 3 Explanation: 12 = 4 + 4 + 4.Example...原创 2020-01-11 11:55:34 · 191 阅读 · 0 评论 -
Leetcode 343. Integer Break
Given a positive integern, break it into the sum ofat leasttwo positive integers and maximize the product of those integers. Return the maximum product you can get.Example 1:Input: 2Output: 1...原创 2020-01-10 08:20:06 · 159 阅读 · 0 评论 -
Leetcode 64. Minimum Path Sum
Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or right at a...原创 2020-01-05 18:06:19 · 131 阅读 · 0 评论 -
Leetcode 120. Triangle
Given 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...原创 2020-01-05 16:10:36 · 143 阅读 · 0 评论 -
Leetcode 236. Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to thedefinition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p...转载 2020-01-04 21:58:16 · 97 阅读 · 0 评论 -
Leetcode 310. Minimum Height Trees
For an undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called min...转载 2019-12-22 16:28:23 · 91 阅读 · 0 评论 -
LeetCode:127 Word Ladder
Given two words (beginWordandendWord), and a dictionary's word list, find the length of shortest transformation sequence frombeginWordtoendWord, such that:Only one letter can be changed at a ti...转载 2019-12-17 23:59:35 · 117 阅读 · 0 评论 -
LeetCode 210: Course Schedule II
There are a total ofncourses you have to take, labeled from0ton-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair...原创 2019-12-15 23:14:50 · 122 阅读 · 0 评论 -
leetcode-863. All Nodes Distance K in Binary Tree
We are given a binary tree (with root noderoot), atargetnode, and an integer valueK.Return a list of the values of allnodes that have a distanceKfrom thetargetnode. The answer can be retur...转载 2019-12-15 23:11:57 · 145 阅读 · 1 评论 -
LeetCode 217: Contains Duplicate
点击打开链接Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every原创 2015-07-05 22:31:41 · 415 阅读 · 0 评论