自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(221)
  • 收藏
  • 关注

原创 红黑树(Red Black Tree)基本性质 + 建树

红黑树:一种特殊的二叉搜索树二叉搜索树:一种树的类型,每个节点最多有两个子节点,其中其左节点一定小于当前节点,右节点一定大于当前节点二叉树的缺点:如果给定的初始序列顺序不好,可能会建出类似于链表的结构,对搜索速度全无助益红黑树的目的:构建一棵趋于平衡的二叉搜索树,杜绝bad case的出现情况。

2023-06-10 15:49:06 806

原创 #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 189 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 176

原创 #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 118

原创 #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 101

原创 #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 84

原创 #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 130

原创 #113 Path Sum II

Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of the node values, not node references.A root-to-leaf path is a p

2022-06-09 21:38:29 96

原创 #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 102

原创 #1139 Largest 1-Bordered Square

DescriptionGiven a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn’t exist in the grid.ExamplesExample 1:Input: grid = [[1,1,1],[1,0,1],[1,1,1]]Output: 9E

2022-05-27 10:41:53 133

原创 #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 140

原创 #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 101

原创 #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 281

原创 #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 281

原创 #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 159

原创 #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 287

原创 #990 Satisfiability of Equality Equations

DescriptionYou are given an array of strings equations that represent relationships between variables where each string equations[i] is of length 4 and takes one of two different forms: “xi==yi” or “xi!=yi”.Here, xi and yi are lowercase letters (not neces

2022-04-28 11:12:39 121

原创 #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 156

原创 #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 87

原创 #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 208

原创 #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 188

原创 #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 704

原创 #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 136

原创 #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 140

原创 #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 179

原创 #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 157

原创 #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 1089

原创 #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 111

原创 #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+2​forn>=0.Given n, return

2022-04-15 08:43:14 108

原创 #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 117

原创 #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 113

原创 #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 66

原创 #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 78

原创 #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 228

原创 #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 111

原创 #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 130

原创 #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 137

原创 #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 157

原创 #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 127

原创 #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 116

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除