自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

leetcode 解题思路

FLAG必经之路

  • 博客(1133)
  • 收藏
  • 关注

原创 Smallest Range Covering Elements from K Lists

You haveklists of sorted integers innon-decreasingorder. Find thesmallestrange that includes at least one number from each of theklists.We define the range[a, b]is smaller than range[c, d]ifb - a < d - cora < cifb - a == d - c....

2022-05-20 14:07:47 272

原创 Parallel Courses III

You are given an integern, which indicates that there arencourses labeled from1ton. You are also given a 2D integer arrayrelationswhererelations[j] = [prevCoursej, nextCoursej]denotes that courseprevCoursejhas to be completedbeforecoursenext...

2022-05-20 12:14:06 224

原创 Shortest Path to Get All Keys

You are given anm x ngridgridwhere:'.'is an empty cell. '#'is a wall. '@'is the starting point. Lowercase letters represent keys. Uppercase letters represent locks.You start at the starting point and one move consists of walking one space in ...

2022-05-16 05:33:38 231

原创 Shortest Path Visiting All Nodes

You have an undirected, connected graph ofnnodes labeled from0ton - 1. You are given an arraygraphwheregraph[i]is a list of all the nodes connected with nodeiby an edge.Returnthe length of the shortest path that visits every node. You may sta...

2022-05-16 03:05:02 126

原创 Pour Water

You are given an elevation map represents as an integer arrayheightswhereheights[i]representing the height of the terrain at indexi. The width at each index is1. You are also given two integersvolumeandk.volumeunits of water will fall at indexk...

2022-05-15 13:36:26 124

原创 Smallest Common Region

You are given some lists ofregionswhere the first region of each list includes all other regions in that list.Naturally, if a regionxcontains another regionythenxis bigger thany. Also, by definition, a regionxcontains itself.Given two region...

2022-05-15 06:48:44 95

原创 Find Longest Duplicate Path in Matrix

Given an integer matrix, find the length of the longest path that have same values. The matrix has no boundary limits. (like, Google Maps - see edit for context)From each cell, you can either move to two directions: horizontal or vertical. You may NOT

2022-05-09 13:01:15 258

原创 Most Profit Assigning Work

You havenjobs andmworkers. You are given three arrays:difficulty,profit, andworkerwhere:difficulty[i]andprofit[i]are the difficulty and the profit of theithjob, and worker[j]is the ability ofjthworker (i.e., thejthworker can only compl...

2022-05-07 11:45:14 224

原创 Shortest Path to Get Food

You are starving and you want to eat food as quickly as possible. You want to find the shortest path to arrive at any food cell.You are given anm x ncharacter matrix,grid, of these different types of cells:'*'is your location. There isexactly one...

2022-05-06 14:46:26 87

原创 Find Nearest Point That Has the Same X or Y Coordinate

You are given two integers,xandy, which represent your current location on a Cartesian grid:(x, y). You are also given an arraypointswhere eachpoints[i] = [ai, bi]represents that a point exists at(ai, bi). A point isvalidif it shares the same x-...

2022-05-04 13:55:40 212

原创 Similar String Groups

Two stringsXandYare similar if we can swap two letters (in different positions) ofX, so thatit equalsY. Also two stringsXandYare similar if they are equal.For example,"tars"and"rats"are similar (swapping at positions0and2), and"rats"a...

2022-05-03 13:42:35 304

原创 Design File System

You are asked to design a file systemthat allows you to create new paths and associate them with different values.The format of a path isone or more concatenated strings of the form:/followed by one or more lowercase English letters. For example, "/l...

2022-05-03 12:34:09 178

原创 Swapping Nodes in a Linked List

You are given theheadof a linked list, and an integerk.Returnthe head of the linked list afterswappingthe values of thekthnode from the beginning and thekthnode from the end (the list is1-indexed).Example 1:Input: head = [1,2,3,4,5], k ...

2022-05-02 14:11:57 439

原创 Rotational Cipher

One simple way to encrypt a string is to "rotate" every alphanumeric character by a certain amount. Rotating a character means replacing it with another character that is a certain number of steps away in normal alphabetic or numerical order.For example,

2022-05-01 13:44:26 147

原创 Is Subsequence

Given two stringssandt, returntrueifsis asubsequenceoft, orfalseotherwise.Asubsequenceof a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative posit...

2022-05-01 11:28:28 118

原创 Strings Differ by One Character

Given a list of stringsdictwhere all the strings are of the same length.Returntrueif there are 2 strings that only differ by 1 character in the same index, otherwise returnfalse.Example 1:Input: dict = ["abcd","acbd", "aacd"]Output: trueExp...

2022-04-30 08:29:16 153

原创 Rank Transform of an Array

Given an array of integersarr, replace each element with its rank.The rank represents how large the element is. The rank has the following rules:Rank is an integer starting from 1. The larger the element, the larger the rank. If two elements are equa.

2022-04-25 06:06:53 131

原创 Dot Product of Two Sparse Vectors

Given two sparse vectors, compute their dot product.Implement classSparseVector:SparseVector(nums)Initializes the object with the vectornums dotProduct(vec)Compute the dot product between the instance ofSparseVectorandvecAsparse vectoris a v...

2022-04-23 13:18:38 276

原创 K-Similar Strings

Stringss1ands2arek-similar(for some non-negative integerk) if we can swap the positions of two letters ins1exactlyktimes so that the resulting string equalss2.Given two anagramss1ands2, return the smallestkfor whichs1ands2arek-simil...

2022-04-20 14:08:48 142

原创 Car Pooling

There is a car withcapacityempty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).You are given the integercapacityand an arraytripswheretrips[i] = [numPassengersi, fromi, toi]indicates that theithtrip hasnumPas...

2022-04-20 08:40:36 200

原创 Minimum Degree of a Connected Trio in a Graph

You are given an undirected graph. You are given an integernwhich is the number of nodes in the graph and an arrayedges, where eachedges[i] = [ui, vi]indicates that there is an undirected edge betweenuiandvi.Aconnected triois a set ofthreenod...

2022-04-20 02:58:06 190

原创 Shortest Path to Get Food

You are starving and you want to eat food as quickly as possible. You want to find the shortest path to arrive at any food cell.You are given anm x ncharacter matrix,grid, of these different types of cells:'*'is your location. There isexactly one...

2022-04-09 02:05:18 193

原创 Minimum Operations to Make a Uni-Value Grid

You are given a 2D integergridof sizem x nand an integerx. In one operation, you canaddxto orsubtractxfrom any element in thegrid.Auni-value gridis a grid where all the elements of it are equal.Returntheminimumnumber of operations to m...

2022-04-07 05:26:54 186

原创 Distinct Subsequences II

Given a string s, returnthe number ofdistinct non-empty subsequencesofs. Since the answer may be very large, return itmodulo109+ 7.Asubsequenceof a string is a new string that is formed from the original string by deleting some (can be none) of ...

2022-04-06 14:20:01 138

原创 Shortest Subarray to be Removed to Make Array Sorted

Given an integer arrayarr, remove a subarray (can be empty) fromarrsuch that the remaining elements inarrarenon-decreasing.Returnthe length of the shortest subarray to remove.Asubarrayis a contiguous subsequence of the array.Example 1:Inp...

2022-04-06 11:51:31 266

原创 Two City Scheduling

A company is planning to interview2npeople. Given the arraycostswherecosts[i] = [aCosti, bCosti],the cost of flying theithperson to cityaisaCosti, and the cost of flying theithperson to citybisbCosti.Returnthe minimum cost to fly every p...

2022-04-06 10:38:12 139

原创 Complete Binary Tree Inserter

Acomplete binary treeis a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.Design an algorithm to insert a new node to a complete binary tree keeping it complete after the inser..

2022-04-05 14:12:00 72

原创 Coin Change 2

You are given an integer arraycoinsrepresenting coins of different denominations and an integeramountrepresenting a total amount of money.Returnthe number of combinations that make up that amount. If that amount of money cannot be made up by any com...

2022-04-04 02:29:15 352

原创 Step-By-Step Directions From a Binary Tree Node to Another

You are given therootof abinary treewithnnodes. Each node is uniquely assigned a value from1ton. You are also given an integerstartValuerepresenting the value of the start nodes, and a different integerdestValuerepresenting the value of the d...

2022-04-01 11:26:11 264

原创 Is Subsequence

Given two stringssandt, returntrueifsis asubsequenceoft, orfalseotherwise.Asubsequenceof a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative posit...

2022-04-01 01:41:03 375

原创 Number of Visible People in a Queue

There arenpeople standing in a queue, and they numbered from0ton - 1inleft to rightorder. You are given an arrayheightsofdistinctintegers whereheights[i]represents the height of theithperson.A person canseeanother person to their right ...

2022-03-30 14:21:02 329

原创 Minimum Moves to Move a Box to Their Target Location

A storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations.The game is represented by anm x ngrid of charactersgridwhere each element is a wall, floor, or box.Your task is to move the box'...

2022-03-28 10:54:01 401

原创 Cutting Ribbons

You are given an integer arrayribbons, whereribbons[i]represents the length of theithribbon, and an integerk. You may cut any of the ribbons into any number of segments ofpositive integerlengths, or perform no cuts at all.For example, if you have...

2022-03-28 01:55:53 261

原创 Binary Search Tree to Greater Sum Tree

Given 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 the sum of all keys greater than the original key in BST.As a reminder, abinary search treeis a tree ...

2022-03-28 01:18:53 348

原创 Angle Between Hands of a Clock

Given two numbers, hour and minutes, return the smaller angle (in degrees) formed between the hour and the minute hand.Answers within 10-5 of the actual value will be accepted as correct.Example 1:Input: hour = 12, minutes = 30Output: 165思路:算h

2022-03-27 12:02:49 368

原创 Strings Differ by One Character

Given a list of stringsdictwhere all the strings are of the same length.Returntrueif there are 2 strings that only differ by 1 character in the same index, otherwise returnfalse.Example 1:Input: dict = ["abcd","acbd", "aacd"]Output: trueExpla...

2022-03-26 12:15:29 519 1

原创 Construct K Palindrome Strings

Given a stringsand an integerk, returntrueif you can use all the characters insto constructkpalindrome strings orfalseotherwise.Example 1:Input: s = "annabelle", k = 2Output: trueExplanation: You can construct two palindromes using all ch...

2022-03-25 09:57:56 113

原创 Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit

Given an array of integersnumsand an integerlimit, return the size of the longestnon-emptysubarray such that the absolute difference between any two elements of this subarray is less than or equal tolimit.Example 1:Input: nums = [8,2,4,7], limit...

2022-03-23 01:11:59 159

原创 Construct Quad Tree

Given an * nmatrixgridof0'sand1'sonly. We want to represent thegridwith a Quad-Tree.Returnthe root of the Quad-Treerepresenting thegrid.Notice that you can assign the value of a node toTrueorFalsewhenisLeafisFalse, and both areacce...

2022-03-22 12:38:06 150

原创 Finding the Users Active Minutes

You are given the logs for users' actions on LeetCode, and an integerk. The logs are represented by a 2D integer arraylogswhere eachlogs[i] = [IDi, timei]indicates that the user withIDiperformed an action at the minutetimei.Multiple userscan per...

2022-03-22 02:04:46 423

空空如也

空空如也

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

TA关注的人

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