自定义博客皮肤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必经之路

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

原创 Reorder Routes to Make All Paths Lead to the City Zero

There arencities numbered from0ton-1andn-1roads such thatthere is only one way to travel between twodifferent cities (this network form a tree).Last year,The ministry of transportdecided to orient the roads in one direction because they are to...

2020-05-31 13:35:46 221

原创 String Compression

Given an array of characters, compress itin-place.The length after compression must always be smaller than or equal to the original array.Every element of the array should be acharacter(not int) of length 1.After you are donemodifying the input a...

2020-05-31 08:15:43 147

原创 Exam Room

In an exam room, there areNseats in a single row, numbered0, 1, 2, ..., N-1.When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in the seat with the l...

2020-05-31 07:42:01 554

原创 Knight Dialer

A chess knight can move as indicated in the chess diagram below:. This time, we place our chess knight on any numbered key of a phone pad (indicated above), and the knight makesN-1hops. Each hop must be from one key to another numbered...

2020-05-31 05:34:46 167

原创 Goat Latin

A sentenceSis given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.We would like to convert the sentence to "Goat Latin"(a made-up language similar to Pig Latin.)The rules of Goat Latin are as foll...

2020-05-30 13:56:54 194

原创 Permutation in String

Given two stringss1ands2, write a function to return true ifs2contains the permutation ofs1. In other words, one of the first string's permutations is thesubstringof the second string.Example 1:Input: s1 = "ab" s2 = "eidbaooo"Output: TrueExp...

2020-05-30 06:07:02 151

原创 Shortest Path in Binary Matrix

In an N by N square grid, each cell is either empty (0) or blocked (1).Aclearpath from top-left to bottom-righthas lengthkif and only if it is composed of cellsC_1, C_2, ..., C_ksuch that:Adjacent cellsC_iandC_{i+1}are connected 8-directiona...

2020-05-30 04:52:51 187

原创 Maximum Width of Binary Tree

Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the same structure as afull binary tree, but some nodes are null.The width of one level is d.

2020-05-29 14:39:14 158

原创 Split Array with Equal Sum

Given an array with n integers, you need to find if there are triplets (i, j, k) which satisfies following conditions:0 < i, i + 1 < j, j + 1 < k < n - 1 Sum of subarrays (0, i - 1), (i + 1, j - 1), (j + 1, k - 1) and (k + 1, n - 1) should b

2020-05-29 13:35:27 246

原创 Maximum Product Subarray

Given an integer arraynums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation:[2,3] has the largest product 6.Example 2:Input: [-2,0,-1..

2020-05-28 14:31:58 142

原创 Find N Unique Integers Sum up to Zero

Given an integern, returnanyarray containingnuniqueintegers such that they add up to 0.Example 1:Input: n = 5Output: [-7,-1,1,3,4]Explanation: These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4].Example 2:Input: n = 3Output: [...

2020-05-28 14:14:27 244

原创 Next Greater Node In Linked List

We are given a linked list withheadas the first node. Let's number thenodes in the list:node_1, node_2, node_3, ...etc.Each node may have anext largervalue: fornode_i,next_larger(node_i)is thenode_j.valsuch thatj > i,node_j.val > nod...

2020-05-28 13:38:07 177

原创 All Elements in Two Binary Search Trees

Given two binary search treesroot1androot2.Return a list containingall the integersfromboth treessorted inascendingorder.Example 1:Input: root1 = [2,1,4], root2 = [1,0,3]Output: [0,1,1,2,3,4]思路:先用inorder traverse,把两个tree变成两个sorted queu...

2020-05-28 12:49:37 174

原创 Exclusive Time of Functions

On asingle threadedCPU, we execute some functions. Each function has a unique id between0andN-1.We store logs in timestamp order that describe when a function is entered or exited.Each log is a string with this format:"{function_id}:{"start" | "...

2020-05-27 13:06:06 279

原创 Check Completeness of a Binary Tree

Given a binary tree, determine if it is acomplete binary tree.Definition of a complete binary tree fromWikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as ..

2020-05-27 12:11:24 123

原创 Minimum Number of Arrows to Burst Balloons

There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordinates don't matter and hence the x-coordinates of start a

2020-05-27 11:41:50 101

原创 Strobogrammatic Number III

A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Write a function to count the total strobogrammatic numbers that exist in the range of low <= num <= high.Example:Input: low = "50", high

2020-05-26 12:54:22 247

原创 Strobogrammatic Number II

A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Find all strobogrammatic numbers that are of length = n.Example:Input: n = 2Output: ["11","69","88","96"]思路:这题就是用dfs来计算里面的,然后回归到最后一层,用里面的结

2020-05-26 12:31:12 214

原创 Swim in Rising Water

On an N x Ngrid, each squaregrid[i][j]represents the elevation at that point(i,j).Now rain starts to fall. At timet, the depth of the water everywhere ist. You can swim from a square to another 4-directionally adjacent square if and only if the ele...

2020-05-26 11:24:15 248

原创 Range Sum Query 2D - Immutable

Given a 2D matrixmatrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1,col1) and lower right corner (row2,col2).The above rectangle (with the red border) is defined by (row1, col1) =(2, 1)and (row2, col2) ...

2020-05-26 10:25:04 128

原创 Add Bold Tag in String && Bold Words in String

Given a stringsand a list of stringsdict, you need to add a closed pair of bold tag<b>and</b>to wrap the substrings in s that exist in dict. If two such substrings overlap, you need to wrap them together by only one pair of closed bold t...

2020-05-26 09:23:52 192

原创 Shortest Palindrome

Given a strings, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.Example 1:Input: "aacecaaa"Output: "aaacecaaa"Example 2:.

2020-05-26 05:48:00 122

原创 [LeetCode] Continuous Subarray Sum

Given a list ofnon-negativenumbers and a targetintegerk, write a function to check if the array has a continuous subarray of size at least 2 that sums up to a multiple ofk, that is, sums up to n*k where n is also aninteger.Example 1:Input: [23, ...

2020-05-26 04:41:54 237

原创 Longest Line of Consecutive One in Matrix

Given a 01 matrixM, find the longest line of consecutive one in the matrix. The line could be horizontal, vertical, diagonal or anti-diagonal.Example:Input:[[0,1,1,0], [0,1,1,0], [0,0,0,1]]Output: 3Hint:The number of elements in the given ma..

2020-05-26 03:05:45 232

原创 Smallest Subtree with all the Deepest Nodes

Given a binary tree rooted atroot, thedepthof each node is the shortest distance to the root.A node isdeepestif it has the largest depth possible amongany node in theentire tree.The subtree of a node is that node, plus the set of all descendants...

2020-05-25 14:59:49 226

原创 Divide Array in Sets of K Consecutive Numbers

Given an array of integersnumsand a positive integerk, find whether it's possible to divide this array intosets ofkconsecutive numbersReturnTrueif its possibleotherwisereturnFalse.Example 1:Input: nums = [1,2,3,3,4,4,5,6], k = 4Output: tr...

2020-05-25 13:34:01 181

原创 Minimum Window Subsequence

Given stringsSandT, find the minimum (contiguous)substringWofS, so thatTis asubsequenceofW.If there is no such window inSthat covers all characters inT, return the empty string"". If there are multiple such minimum-length windows, return ...

2020-05-25 13:17:25 175

原创 String Transforms Into Another String

Given two stringsstr1andstr2of the same length, determine whether you can transformstr1intostr2by doingzero or moreconversions.In one conversion you can convertalloccurrences of one character instr1toanyother lowercase English character....

2020-05-25 10:07:16 223

原创 Divide Chocolate

You have one chocolate bar that consists of some chunks. Each chunk has its own sweetness given by the arraysweetness.You want to share the chocolate with yourKfriends so you start cutting the chocolate bar intoK+1pieces usingKcuts, each piece con...

2020-05-25 07:52:16 418

原创 Next Greater Element II

Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first greater number to its traversing-order next in the array, w

2020-05-25 05:41:38 188

原创 Counting Bits

Given a non negative integer numbernum. For every numbersiin the range0 ≤ i ≤ numcalculate the number of 1's in their binary representation and return them as an array.Example 1:Input: 2Output: [0,1,1]Example 2:Input: 5Output: [0,1,1,2,1,2...

2020-05-25 05:11:03 157

原创 Maximum Number of Vowels in a Substring of Given Length

Given a stringsand an integerk.Returnthe maximum number of vowel lettersin any substring ofswithlengthk.Vowel lettersinEnglish are(a, e, i, o, u).Example 1:Input: s = "abciiidef", k = 3Output: 3Explanation: The substring "iii" con...

2020-05-25 04:52:10 196

原创 Pseudo-Palindromic Paths in a Binary Tree

Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to bepseudo-palindromicif at least one permutation of the node values in the path is a palindrome.Return the number ofpseudo-palindromicpaths going from t...

2020-05-25 02:51:53 263

原创 Max Dot Product of Two Subsequences

Given two arraysnums1andnums2.Return the maximum dot productbetweennon-emptysubsequences of nums1 and nums2 with the same length.A subsequence of a array is a new array which is formed from the original array by deleting some (can be none) of the...

2020-05-24 13:17:02 306

原创 Random Pick with Weight

Given an arraywof positive integers, wherew[i]describes the weight of indexi,write a functionpickIndexwhich randomlypicks an indexin proportionto its weight.Note:1 <= w.length <= ...

2020-05-23 02:03:31 312

原创 Valid Parenthesis String

Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid. We define the validity of a string by these rules:Any left parenthesis'('must have a corresponding right parenthesis')'...

2020-05-22 13:38:03 263

原创 Shortest Way to Form String

From any string, we can form asubsequenceof that string by deleting some number of characters (possibly no deletions).Given two stringssourceandtarget, return the minimum number of subsequences ofsourcesuch that their concatenation equalstarget. ...

2020-05-22 12:44:38 220

原创 Implement Magic Dictionary

Implement a magic directory withbuildDict, andsearchmethods.For the methodbuildDict, you'll be given a list of non-repetitive words to build a dictionary.For the methodsearch, you'll be given a word, and judge whether if you modifyexactlyone cha...

2020-05-22 12:00:25 143

原创 Insert into a Binary Search Tree

Given the root node of a binary search tree (BST) and a value to be inserted into the tree,insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.Note th.

2020-05-22 07:20:18 170

原创 Maximum Swap

Given a non-negative integer, you could swap two digitsat mostonce to get the maximum valued number. Return the maximum valued number you could get.Example 1:Input: 2736Output: 7236Explanation: Swap the number 2 and the number 7.Example 2:I..

2020-05-21 14:33:10 173

空空如也

空空如也

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

TA关注的人

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