![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode日练
文章平均质量分 82
BabyFennec
23Aug前小小目标冲完200题
展开
-
Leetcode日练笔记39 [二叉树recursion专题] #104 #101 Maximum Depth of Binary Tree & Symmetric Tree {Python}
Leetcode日练笔记39 【二叉树专题】Recursive思路训练 #104 & #101 Maximum Depth of Binary Tree & Symmetric Tree {Python}原创 2022-07-12 19:12:52 · 359 阅读 · 1 评论 -
Leetcode日练笔记38 [二叉树专题] #102 Binary Tree Level Order Traversal
Leetcode日练笔记 【二叉树专题】 BFS #102 Binary Tree Level Order Traversal (Python) Iterative + Recursive思路原创 2022-07-12 12:28:09 · 215 阅读 · 0 评论 -
Leetcode日练笔记37 [二叉树专题] #145 Binary Tree Postorder Traversal
postorder traversal python原创 2022-07-02 16:50:24 · 130 阅读 · 0 评论 -
Leetcode36 [二叉树专题] 基本概念 & #144 #94 Binary Tree Preorder Traversal & Binary Tree Inorder Traversal
Leetcode 【Binary Tree专题】#144 Preorder Traversal & #94 Binary Tree Inorder Traversal (Python解法)原创 2022-06-21 12:06:45 · 205 阅读 · 0 评论 -
Leetcode日练笔记35 [Linked List专题] #138 #61 Copy List with Random Pointer & Rotate List
Leetcode Linked List专题 #138 Copy List with Random Pointer & #61 Rotate List【Python解法】原创 2022-06-19 13:58:52 · 76 阅读 · 0 评论 -
Leetcode34[Linked List专题] #430 #708 Flatten a Multilevel Doubly Linked List & Insert into a Cyclic S
Leetcode [Linked List专题] #430 Flatten a Multilevel Doubly Linked List Python解法原创 2022-06-18 23:39:48 · 114 阅读 · 0 评论 -
Leetcode日练笔记33 [linked list专题] #21 #2 Merge Two Sorted Lists & Add Two Numbers
Leetcode Linked List专题 #21 Merged Two Linked List & #2 Add Two Numbers Python解法原创 2022-06-16 13:55:00 · 187 阅读 · 0 评论 -
Leetcode日练笔记32 [Linked List专题] #328 #234 Odd Even Linked List & Palindrome Linked List
Leetcode 链表专题 #328 奇偶点链表 #234 回文结构的判断 Python解法原创 2022-06-13 12:07:22 · 93 阅读 · 0 评论 -
Leetcode日练笔记31 #19 #206 # 203 Rmv Nth Node From End & Reverse Linked List & Rmv Linked List Elements
Leetcode 链表专题 #19 #206 #203 Remove Nth Node From End of List & Reverse Linked List & remove element from the linked list原创 2022-06-11 15:17:10 · 124 阅读 · 0 评论 -
Leetcode日练笔记30 [Linked List专题] #142 #160 Linked List Cycle II & Intersection of Two Linked Lists
Leetcode 链表专题 #142 Linked List Cycle II #160 Intersections of two Linked List (Python解法)原创 2022-06-10 11:37:57 · 101 阅读 · 0 评论 -
Leetcode日练笔记29 [Linked List专题] #707 #141 Design Linked List & Linked List Cycle
Leetcode 链表专题 #707 #141 Python解法原创 2022-06-09 10:58:38 · 109 阅读 · 0 评论 -
Leetcode日练笔记28 #151 #557 Reverse Words in a String & Reverse Words in a String III
Leetcode 151和557 reverse words in a string Python解法原创 2022-06-07 16:10:37 · 106 阅读 · 0 评论 -
Leetcode日练笔记27 #189 #119 Rotate Array & Pascal‘s Triangle II
Given an array, rotate the array to the right byksteps, wherekis non-negative.解题思路:for循环range(k), 然后用pop()去掉最后一位并通过insert()加入数列最前面。class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anyt...原创 2022-05-31 15:59:58 · 113 阅读 · 0 评论 -
Leetcode日练笔记26 #561 #209 Array Partition I & Minimum Size Subarray Sum
#561 Array Partition IGiven an integer arraynumsof2nintegers, group these integers intonpairs(a1, b1), (a2, b2), ..., (an, bn)such that the sum ofmin(ai, bi)for alliismaximized. Returnthe maximized sum.解题思路:能获得pair里min之和的最大值策略是从小到大排列,...原创 2022-05-30 11:25:04 · 116 阅读 · 0 评论 -
Leetcode日练笔记25 #14 #344 Longest Common Prefix & Reverse String
#14 Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string"".解题思路:1.for循环range(最短的元素)作为idx2.以第一个元素[idx]为比较参照点,对比strs里每一个元素[idx]3.全部相等的话,.原创 2022-05-29 14:11:47 · 103 阅读 · 0 评论 -
Leetcode日练笔记24 #67 #28 Add Binary & Implement strStr()
#67 Add BinaryGiven two binary stringsaandb, returntheir sum as a binary string.解题思路:1. 考虑到 string A B 的长度可能不一样所以先补齐零。2. 然后将string A和B 同一个index的数字求和之后赋予给新的string,new3. 用for循环去从后往前看new每一个数位是不是大于2。逢二进一。4.将new转变为string输出。class Solution: ...原创 2022-05-28 18:30:07 · 121 阅读 · 0 评论 -
Leetcode日练笔记23 #54 #118 Spinal Matrix & Pascal‘s Triangle
#54 Spiral MatrixGiven anm x nmatrix, returnall elements of thematrixin spiral order.解题思路:for循环m*n次,然后先column+=1,当column遇到最大值时,再row+=1。等到row也到了最大值,就掉头(体现为d *= -1),column-=1,当column遇到最小值时,再row-=1.每次掉头,都要改变row和column的极限值,因为读过数的idx就不能要了。要么是改row的...原创 2022-05-27 16:45:00 · 155 阅读 · 0 评论 -
Leetcode日练笔记22 #66 #498 Plus One & Diagonal Traverse
#66 Plus OneYou are given alarge integerrepresented as an integer arraydigits, where eachdigits[i]is theithdigit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not ...原创 2022-05-26 22:00:41 · 109 阅读 · 0 评论 -
Leetcode日练笔记21 #724 #747 Find Pivot Index & Largest Number At Least Twice of Others
#724 Find Pivot IndexGiven an array of integersnums, calculate thepivot indexof this array.Thepivot indexis the index where the sum of all the numbersstrictlyto the left of the index is equal to the sum of all the numbersstrictlyto the index...原创 2022-05-25 21:45:12 · 91 阅读 · 0 评论 -
Leetcode日练笔记20 #414 #448 Third Maximum Number & Find All Numbers Disappeared in an Array
#414 Third Maximum NumberGiven an integer arraynums, returnthethird distinct maximumnumber in this array. If the third maximum does not exist, return themaximumnumber.解题思路:1.先找出数列中的最大值,然后删掉2.重复第一步3.再找出此时数列中的最大值,return以上是数列中有第三个最大值存在的情况。...原创 2022-05-25 19:16:50 · 198 阅读 · 0 评论 -
Leetcode日练笔记19 #487 Max Consecutive Ones II (Medium)
#487 Max Consecutive Ones II (Medium)Given a binary arraynums, returnthe maximum number of consecutive1's in the array if you can flip at most one0.解题思路:因为最多可以翻转一个0,那么等同于0所包围的1可以看成可用于加法的有效片段。结果就是取邻近的两个片段之和的最大值再加1。edge case是,整个数列没有0,或者只有1个0,那么...原创 2022-05-22 20:53:17 · 1118 阅读 · 0 评论 -
Leetcode日练笔记18 #905 #1051 Sort Array By Parity & Height Checker
#905 Sort Array By ParityGiven an integer arraynums, move all the even integers at the beginning of the array followed by all the odd integers.Returnany arraythat satisfies this condition.解题思路:沿用上次搜到#283 move zeroes Zitao Wang的思路,用两指针解,偶数就互换,奇...原创 2022-05-20 23:57:44 · 1097 阅读 · 0 评论 -
Leetcode日练17 #1299 #283 Replace Elements with Greatest element on the Right side & Move Zeroes
#1299 Replace Elements with Greatest Element on Right SideGiven an arrayarr,replace every element in that array with the greatest element among the elements to itsright, and replace the last element with-1.After doing so, return the array.解题思路:...原创 2022-05-18 15:28:02 · 149 阅读 · 0 评论 -
Leetcode日练笔记16 #1346 #941 Check If N and Its Double Exist & Valid Mountain Array
#Check If N and Its Double ExistGiven an arrayarrof integers, check if there exists two integersNandMsuch thatNis the double ofM( i.e.N = 2 * M).More formally check if there existstwo indicesiandjsuch that :i != j 0 <= i, j <...原创 2022-05-17 00:45:59 · 800 阅读 · 0 评论 -
Leetcode日练笔记15 #27 # 26 Remove Element & Remove Duplicates from Sorted Array
#27 Remove ElementGiven an integer arraynumsand an integerval, remove all occurrences ofvalinnumsin-place. The relative order of the elements may be changed.Since it is impossible to change the length of the array in some languages, you must ins...原创 2022-05-15 21:35:47 · 236 阅读 · 0 评论 -
Leetcode日练笔记14 #1089 #88 Duplicate Zeros & Merge Sorted Array
#1089 Duplicate ZerosGiven a fixed-length integer arrayarr, duplicate each occurrence of zero, shifting the remaining elements to the right.Notethat elements beyond the length of the original array are not written. Do the above modifications to the ..原创 2022-04-16 22:24:08 · 214 阅读 · 0 评论 -
Leetcode日练笔记13 #485 #1295 #977 Max Consecutive 1s & Find Nums with Even Number of Digits & Squares
#485 Max Consecutive OnesGiven a binary arraynums, returnthe maximum number of consecutive1's in the array.解题思路:判断是不是1,是的话counter开始计数。遇到零的话,把counter的数字与之前的比较后取大的数。然后重新计数。class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -&...原创 2022-04-14 16:40:53 · 494 阅读 · 0 评论 -
Leetcode日练笔记12 #287 #4 Find the Duplicate Number (Medium) & Median of Two Sorted Array (Hard)
#287 Find the Duplicate Number (Python)原创 2022-03-24 22:51:47 · 132 阅读 · 0 评论 -
Leetcode日练笔记11 #350 #167 Intersection of Two Arrays II & Two Sum II - Input array is sorted
#350 Intersection of Two Arrays IIGiven two integer arraysnums1andnums2, returnan array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result inany order.解题思路:还是用回之...原创 2022-03-23 21:51:47 · 1611 阅读 · 0 评论 -
Leetcode日练笔记10 #154 #349 Find Minimum in Rotated Sorted Array II (Hard) & Intersection of Two Arrays
#154Find Minimum in Rotated Sorted Array II (Hard)Suppose an array of lengthnsorted in ascending order isrotatedbetween1andntimes. For example, the arraynums = [0,1,4,4,5,6,7]might become:[4,5,6,7,0,1,4]if it was rotated4times. [0,1,4,4...原创 2022-03-23 17:04:19 · 526 阅读 · 0 评论 -
Leetcode日练笔记9 #50 #367 #744 Power & Valid Perfect Square & Find Smallest Letter Greater Than Target
#50Pow(x, n)Implementpow(x, n), which calculatesxraised to the powern(i.e.,xn).原创 2022-03-22 16:23:36 · 90 阅读 · 0 评论 -
Leetcode日练笔记8 #702 Search in a Sorted Array of Unknown Size (Medium)
#702Search in a Sorted Array of Unknown Size题目:This is aninteractive problem.You have a sorted array ofuniqueelements and anunknown size. You do not have an access to the array but you can use theArrayReaderinterface to access it. You can call...原创 2022-03-20 23:09:25 · 418 阅读 · 0 评论 -
Leetcode日练笔记7 #270 Closest Binary Search Tree Value
#270Closest Binary Search Tree ValueGiven therootof a binary search tree and atargetvalue, returnthe value in the BST that is closest to thetarget.解题思路:本来一拿到题,完全没有头绪。看example后。好像直接对root的list直接sorted,按diff从小到大排取最小的就好。但是忘了树节点和list的对应关系了。I...原创 2022-03-18 22:08:26 · 226 阅读 · 0 评论 -
Leetcode日练笔记6 #162 及 Binary Search Template 总结
# 162 Find peak elementA peak element is an element that is strictly greater than its neighbors.Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.You may原创 2022-03-16 22:08:33 · 113 阅读 · 0 评论 -
Leetcode日练5 #658 Find K closest element
#658 Find K Closest ElementsGiven a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order.An integer a is closer to x than an integer b if:|a - x| < |b原创 2022-03-12 00:02:59 · 407 阅读 · 0 评论 -
Leetcode日练4 #34 search for a range
第三种二分法是要求当下算出中值的左右相邻的值。也就是说每一次都要判别至少3个值。最后是应该剩两个值。#34Search for a RangeGiven an array of integersnumssorted in non-decreasing order, find the starting and ending position of a giventargetvalue.Iftargetis not found in the array, return[-...原创 2022-03-08 23:18:06 · 7564 阅读 · 0 评论 -
Leetcode日练笔记3 #278 #162 #153 First bad version & Find peak element & Find minimum in rotated array
Template 2 是让最后一步只剩2个值,一个是left pointer,另一个是right pointer。如果不管哪个,若和目标值不一致,则两个pointer合并为一个,最后terminate while循环,并post process最后一个值是否与目标值同。不同则输出-1。(Q:暂时没理解为啥和template 1 不同?先🐴)# 278 First Bad VersionYou are a product manager and currently leading a team原创 2022-03-07 00:37:01 · 6373 阅读 · 0 评论 -
Leetcode日练笔记2 #69 #374 #33 sqrt() & Guess Number Higher or Lower & Search in Rotated Sorted Array
凡是要在一堆元素里寻找某个特定元素或其index的时候,都用binary search。#69 求开根Given a non-negative integerx,compute and returnthe square root ofx.Since the return typeis an integer, the decimal digits aretruncated, and onlythe integer partof the resultis returned.No...原创 2022-03-03 15:28:44 · 400 阅读 · 0 评论 -
Leetcode日练笔记1 #704 Binary Search (Easy)
刚自学完 Codecademy 的数据结构,因为上面的随练比较少,加上对知识点的掌握和理解还不够,所以开始在 Leetcode 上根据 b站 Christinaaaya 的建议,按知识板块从易到难做题。用的是 Leetcode 上 explore 版块,先从 binary search 入手。背景一章,给的是 #704.题目:Given an array of integersnumswhich is sorted in ascending order, and an integ..原创 2022-03-02 13:50:22 · 255 阅读 · 0 评论