![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 74
yoyooyooo
这个作者很懒,什么都没留下…
展开
-
#104 Maximum Depth of Binary Tree
Given the root of a binary tree, return its maximum depth.A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Example 1:Example 2:Constraints:dfs原创 2022-06-16 17:23:12 · 238 阅读 · 1 评论 -
#107 Binary Tree Level Order Traversal II
Given the root of a binary tree, return the bottom-up level order traversal of its nodes’ values. (i.e., from left to right, level by level from leaf to root).Example 1:Example 2:Example 3:Constraints:没啥好说的,bfs原创 2022-06-15 20:51:30 · 187 阅读 · 0 评论 -
#437 Path Sum III
Given the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum.The path does not need to start or end at the root or a leaf, but it must go downwards (i.e., traveling only fr原创 2022-06-13 17:34:38 · 124 阅读 · 0 评论 -
#934 Shortest Bridge
You are given an n x n binary matrix grid where 1 represents land and 0 represents water.An island is a 4-directionally connected group of 1’s not connected to any other 1’s. There are exactly two islands in grid.You may change 0’s to 1’s to connect the tw原创 2022-06-13 14:30:31 · 108 阅读 · 0 评论 -
#141 Linked List Cycle
Given head, the head of a linked list, determine if the linked list has a cycle in it.There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denot原创 2022-06-10 10:53:16 · 95 阅读 · 0 评论 -
#981 Time Based Key-Value Store
Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key’s value at a certain timestamp.Implement the TimeMap class:Example 1:Constraints:是用一个二分查找的思路,因为在constrain里面说了 “All th原创 2022-06-10 10:30:01 · 141 阅读 · 0 评论 -
#886 Possible Bipartition
We want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not go into the same group.Given the integer n and the array dislikes where dislikes[i] = [ai, bi] indicates原创 2022-06-09 20:39:37 · 109 阅读 · 0 评论 -
#299 Bulls and Cows
DescriptionYou are playing the Bulls and Cows game with your friend.You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:The number of “bulls”, which a原创 2022-05-13 12:42:47 · 152 阅读 · 0 评论 -
#470 Implement Rand10() Using Rand7()
DescriptionGiven the API rand7() that generates a uniform random integer in the range [1, 7], write a function rand10() that generates a uniform random integer in the range [1, 10]. You can only call the API rand7(), and you shouldn’t call any other API.原创 2022-05-13 11:38:54 · 118 阅读 · 0 评论 -
#704 Binary Search
DescriptionGiven an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.You must write an algorithm with O(log n) runti原创 2022-05-04 23:04:46 · 288 阅读 · 0 评论 -
#700 Search in a Binary Search Tree
DescriptionYou are given the root of a binary search tree (BST) and an integer val.Find the node in the BST that the node’s value equals val and return the subtree rooted with that node. If such a node does not exist, return null.ExamplesExample 1:I原创 2022-05-04 22:45:42 · 285 阅读 · 0 评论 -
#206 Reverse Linked List
DescriptionGiven the head of a singly linked list, reverse the list, and return the reversed list.ExamplesExample 1:Input: head = [1,2,3,4,5]Output: [5,4,3,2,1]Example 2:Input: head = [1,2]Output: [2,1]Example 3:Input: head = []Output: []原创 2022-05-04 22:38:40 · 170 阅读 · 0 评论 -
#752 Open the Lock
DescriptionYou have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’. The wheels can rotate freely and wrap around: for example we can turn ‘9’ to be ‘0’, or ‘0’ to be ‘9’. Each move原创 2022-04-28 23:18:47 · 296 阅读 · 0 评论 -
#123 Best Time to Buy and Sell Stock III
DescriptionYou are given an array prices where prices[i] is the price of a given stock on the ith day.Find the maximum profit you can achieve. You may complete at most two transactions.Note: You may not engage in multiple transactions simultaneously (i.原创 2022-04-28 10:55:32 · 176 阅读 · 0 评论 -
#122 Best Time to Buy and Sell Stock II
DescriptionYou are given an integer array prices where prices[i] is the price of a given stock on the ith day.On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can buy it原创 2022-04-26 23:19:02 · 101 阅读 · 0 评论 -
#212 Word Search II
DescriptionGiven an m x n board of characters and a list of strings words, return all words on the board.Each word must be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same原创 2022-04-23 21:01:18 · 216 阅读 · 0 评论 -
#1143 Longest Common Subsequence
DescriptionGiven two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.A subsequence of a string is a new string generated from the original string with some characters (can be non原创 2022-04-21 21:25:55 · 196 阅读 · 0 评论 -
#952 Largest Component Size by Common Factor
DescriptionYou are given an integer array of unique positive integers nums. Consider the following graph:There are nums.length nodes, labeled nums[0] to nums[nums.length - 1],There is an undirected edge between nums[i] and nums[j] if nums[i] and nums[j]原创 2022-04-17 12:59:49 · 725 阅读 · 0 评论 -
#221 Maximal Square
DescriptionGiven an m x n binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.ExamplesExample 1:Input: matrix = [[“1”,“0”,“1”,“0”,“0”],[“1”,“0”,“1”,“1”,“1”],[“1”,“1”,“1”,“1”,“1”],[“1”,“0”,“0”,“1”,“0”原创 2022-04-17 09:00:19 · 142 阅读 · 0 评论 -
#931 Minimum Falling Path Sum
DescriptionGiven an n x n array of integers matrix, return the minimum sum of any falling path through matrix.A falling path starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/r原创 2022-04-16 10:27:00 · 147 阅读 · 0 评论 -
#211 Design Add and Search Words Data Structure
DescriptionDesign a data structure that supports adding new words and finding if a string matches any previously added string.Implement the WordDictionary class:WordDictionary() Initializes the object.void addWord(word) Adds word to the data structure,原创 2022-04-16 10:13:46 · 209 阅读 · 0 评论 -
#216 Combination Sum III
DescriptionFind all valid combinations of k numbers that sum up to n such that the following conditions are true:Only numbers 1 through 9 are used.Each number is used at most once.Return a list of all possible valid combinations. The list must not cont原创 2022-04-16 09:38:36 · 163 阅读 · 0 评论 -
#120 Triangle
DescriptionGiven a triangle array, return the minimum path sum from top to bottom.For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 o原创 2022-04-15 10:22:43 · 1092 阅读 · 0 评论 -
#121 Best Time to Buy and Sell Stock
DescriptionYou are given an array prices where prices[i] is the price of a given stock on the ith day.You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.Return the max原创 2022-04-15 09:21:52 · 114 阅读 · 0 评论 -
#1137 N-th Tribonacci Number
DescriptionThe Tribonacci sequence Tn is defined as follows:T0=0,T1=1,T2=1,andTn+3=Tn+Tn+1+Tn+2forn>=0.T_0 = 0, T_1 = 1, T_2 = 1, and T_{n+3} = T_n + T_{n+1} + T_{n+2} for n >= 0.T0=0,T1=1,T2=1,andTn+3=Tn+Tn+1+Tn+2forn>=0.Given n, return原创 2022-04-15 08:43:14 · 119 阅读 · 0 评论 -
#1218 Longest Arithmetic Subsequence of Given Difference
DescriptionGiven an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference.A subsequence is原创 2022-04-12 12:51:57 · 131 阅读 · 0 评论 -
#239 Sliding Window Maximum
DescriptionYou are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one positi原创 2022-04-12 10:39:58 · 126 阅读 · 0 评论 -
#733. Flood Fill
DescriptionAn image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image.You are also given three integers sr, sc, and newColor. You should perform a flood fill on the image starting from the pixel image原创 2022-04-11 11:40:17 · 71 阅读 · 0 评论 -
#303 Range Sum Query - Immutable
DescriptionGiven an integer array nums, handle multiple queries of the following type:Calculate the sum of the elements of nums between indices left and right inclusive where left <= right.Implement the NumArray class:NumArray(int[] nums) Initialize原创 2022-04-11 11:17:58 · 87 阅读 · 0 评论 -
#784 Letter Case Permutation
DescriptionGiven a string s, you can transform every letter individually to be lowercase or uppercase to create another string.Return a list of all possible strings we could create. Return the output in any order.ExamplesExample 1:Input: s = “a1b2”O原创 2022-04-11 11:04:06 · 235 阅读 · 0 评论 -
#695 Max Area of Island
DescriptionYou are given an m x n binary matrix grid. An island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.The area of an island is the numbe原创 2022-04-10 10:57:23 · 118 阅读 · 0 评论 -
#746 Min Cost Climbing Stairs
DescriptionYou are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps.You can either start from the step with index 0, or the step with index 1.Return the minimu原创 2022-04-10 10:19:25 · 135 阅读 · 0 评论 -
#676 Implement Magic Dictionary
DescriptionDesign a data structure that is initialized with a list of different words. Provided a string, you should determine if you can change exactly one character in this string to match any word in the data structure.Implement the MagicDictionary cl原创 2022-04-10 09:51:17 · 147 阅读 · 0 评论 -
#147 Insertion Sort List
DescriptionGiven the head of a singly linked list, sort the list using insertion sort, and return the sorted list’s head.The steps of the insertion sort algorithm:Insertion sort iterates, consuming one input element each repetition and growing a sorted原创 2022-04-09 13:42:00 · 164 阅读 · 0 评论 -
#108 Convert Sorted Array to Binary Search Tree
DescriptionGiven an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs原创 2022-04-09 10:09:08 · 135 阅读 · 0 评论 -
#102 Binary Tree Level Order Traversal
DescriptionGiven the root of a binary tree, return the level order traversal of its nodes’ values. (i.e., from left to right, level by level).ExamplesExample 1:Input: root = [3,9,20,null,null,15,7]Output: [[3],[9,20],[15,7]]Example 2:Input: root原创 2022-04-09 09:41:01 · 120 阅读 · 0 评论 -
#131 Palindrome Partitioning
DescriptionGiven a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.A palindrome string is a string that reads the same backward as forward.ExamplesExample 1:Input: s =原创 2022-04-08 12:08:28 · 579 阅读 · 0 评论 -
#129 Sum Root to Leaf Numbers
DescriptionYou are given the root of a binary tree containing digits from 0 to 9 only.Each root-to-leaf path in the tree represents a number.For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123.Return the total sum of all root原创 2022-04-08 10:01:02 · 139 阅读 · 0 评论 -
#1105 Filling Bookcase Shelves
DescriptionYou are given an array books where books[i] = [thicknessi, heighti] indicates the thickness and height of the ith book. You are also given an integer shelfWidth.We want to place these books in order onto bookcase shelves that have a total widt原创 2022-04-07 14:03:25 · 209 阅读 · 0 评论 -
#96 Unique Binary Search Trees
DescriptionGiven an integer n, return the number of structurally unique BST’s (binary search trees) which has exactly n nodes of unique values from 1 to n.ExamplesExample 1:Input: n = 3Output: 5Example 2:Input: n = 1Output: 1Constraints:1 &原创 2022-04-07 08:52:50 · 118 阅读 · 0 评论