![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 59
1LOVESJohnny
这个作者很懒,什么都没留下…
展开
-
LeetCode|230. Kth Smallest Element in a BST
目标是找第k个大小的数值,需要先遍历到最左边的节点,然后按照中序遍历递归。BST树的特色是:左子树 < 根节点 < 右子树。从最左子节点开始,每次新的递归k = k - 1。原创 2024-06-07 05:21:43 · 279 阅读 · 0 评论 -
LeetCode|2331. Evaluate Boolean Binary Tree
【代码】LeetCode|2331. Evaluate Boolean Binary Tree。原创 2024-06-07 00:46:59 · 636 阅读 · 0 评论 -
LeetCode|1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree
最主要的问题在于需要弄清楚python函数内局部变量和全局变量的传递关系。简单的二叉树遍历问题,仍然在熟悉python的语法。这道简单题写了很长时间,语法还是不太熟悉。原创 2024-06-07 00:14:33 · 408 阅读 · 0 评论 -
LeetCode|938. Range Sum of BST
开启python刷题时代,主要也是为了面试。原创 2024-06-06 19:39:31 · 471 阅读 · 0 评论 -
LeetCode|700. Search in Binary Search Tree
简单不考虑BST的特性,直接遍历全部二叉树的所有节点。当找到目标节点后,即直接返回。原创 2024-05-09 00:54:03 · 405 阅读 · 0 评论 -
LeetCode|501. Find Mode in Binary Search Tree
时隔若干年后,我又开始刷leetcode了,看看这次会刷多少。原创 2024-04-09 22:21:57 · 410 阅读 · 1 评论 -
LeetCode | 876. Middle of the Linked List
Given the head of a singly linked list, return the middle node of the linked list.If there are two middle nodes, return the second middle node.Input: head = [1,2,3,4,5]Output: [3,4,5]Explanation: The middle node of the list is node 3.Input: head = [1,2,3原创 2022-06-30 23:54:46 · 194 阅读 · 0 评论 -
LeetCode | 784. Letter Case Permutation
Given 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.Input: s = “a1b2”Output: [“a1b2”,“a1B2”,“A1b2”,“A1B2”原创 2022-06-30 23:42:45 · 145 阅读 · 0 评论 -
LeetCode | 771. Jewels and Stones
You’re given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels.Letters are ca原创 2022-06-30 23:40:21 · 167 阅读 · 0 评论 -
LeetCode | 725. Split Linked List in Parts
Given the head of a singly linked list and an integer k, split the linked list into k consecutive linked list parts.The length of each part should be as equal as possible: no two parts should have a size differing by more than one. This may lead to some pa原创 2022-06-30 23:37:06 · 173 阅读 · 0 评论 -
LeetCode | 719. Find K-th Smallest Pair Distance
The distance of a pair of integers a and b is defined as the absolute difference between a and b.Given an integer array nums and an integer k, return the kth smallest distance among all the pairs nums[i] and nums[j] where 0原创 2022-06-30 23:34:00 · 1407 阅读 · 0 评论 -
LeetCode | 707. Design Linked List
Design your implementation of the linked list. You can choose to use a singly or doubly linked list.A node in a singly linked list should have two attributes: val and next. val is the value of the current node, and next is a pointer/reference to the next原创 2022-06-30 23:30:17 · 148 阅读 · 0 评论 -
LeetCode | 693. Binary Number with Alternating Bits
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.原创 2022-05-31 21:27:13 · 122 阅读 · 0 评论 -
LeetCode | 680. Valid Palindrome II
Given a string s, return true if the s can be palindrome after deleting at most one character from it.原创 2022-05-31 21:24:44 · 155 阅读 · 0 评论 -
LeetCode | 665. Non-decreasing Array
Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element.We define an array is non-decreasing if nums[i]原创 2022-05-31 21:21:23 · 164 阅读 · 0 评论 -
LeetCode | 658. Find K Closest Elements
Given 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原创 2022-05-31 21:18:54 · 113 阅读 · 0 评论 -
LeetCode | 647. Palindromic Substrings
Given a string s, return the number of palindromic substrings in it.A string is a palindrome when it reads the same backward as forward.A substring is a contiguous sequence of characters within the string.原创 2022-05-31 21:15:53 · 139 阅读 · 0 评论 -
LeetCode | 639. Decode Ways II
.题目A message containing letters from A-Z can be encoded into numbers using the following mapping:‘A’ -> “1”‘B’ -> “2”…‘Z’ -> “26”To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of原创 2022-04-30 22:07:14 · 337 阅读 · 0 评论 -
LeetCode | 637. Average of Levels in Binary Tree
.题目Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10-5 of the actual answer will be accepted.Example 1:Input: root = [3,9,20,null,null,15,7]Output: [3.00000,14.50000,11.000原创 2022-04-30 22:02:43 · 205 阅读 · 0 评论 -
LeetCode | 628. Maximum Product of Three Numbers
.题目Given an integer array nums, find three numbers whose product is maximum and return the maximum product.Example 1:Input: nums = [1,2,3]Output: 6Example 2:Input: nums = [1,2,3,4]Output: 24Example 3:Input: nums = [-1,-2,-3]Output: -6Constraint原创 2022-04-30 21:57:43 · 163 阅读 · 0 评论 -
LeetCode | 617. Merge Two Binary Trees
.题目You are given two binary trees root1 and root2.Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree. The merge rule is th原创 2022-03-31 22:03:08 · 231 阅读 · 0 评论 -
LeetCode | 605. Can Place Flowers
.题目You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.Given an integer array flowerbed containing 0’s and 1’s, where 0 means empty and 1 means not empty, and an intege原创 2022-03-31 21:58:18 · 375 阅读 · 0 评论 -
LeetCode | 872. Leaf-Similar Trees
.题目Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence.For example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8).Two binary trees are considered leaf-similar原创 2022-03-31 21:46:01 · 1154 阅读 · 0 评论 -
LeetCode | 581. Shortest Unsorted Continuous Subarray
.题目Given an integer array nums, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order.Return the shortest such subarray and output its length.Example 1:I原创 2022-02-28 23:16:46 · 7329 阅读 · 0 评论 -
LeetCode | 561. Array Partition I
.题目Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), …, (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.Example 1:Input: nums = [1,4,3,2]Output: 4Explanation:原创 2022-01-31 22:01:47 · 507 阅读 · 0 评论 -
LeetCode | 557. Reverse Words in a String III
.题目Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: s = “Let’s take LeetCode contest”Output: “s’teL ekat edoCteeL tsetnoc”Example 2:Input: s =原创 2021-12-31 17:19:26 · 196 阅读 · 1 评论 -
LeetCode | 541. Reverse String II
.题目Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string.If there are fewer than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k c原创 2021-12-31 17:14:11 · 231 阅读 · 0 评论 -
LeetCode | 524. Longest Word in Dictionary through Deleting
.题目Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the longest word with the smallest lexico原创 2021-12-30 21:50:00 · 519 阅读 · 0 评论 -
LeetCode | 451. Sort Characters By Frequency
题目Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.Return the sorted string. If there are multiple answers, return any of them.Example 1:原创 2021-12-01 10:24:13 · 191 阅读 · 0 评论 -
LeetCode | 521. Longest Uncommon Subsequence I
题目Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If the longest uncommon subsequence does not exist, return -1.An uncommon subsequence between two strings is a string that is a subsequence of one but not原创 2021-11-30 23:25:33 · 376 阅读 · 0 评论 -
LeetCode | 516. Longest Palindromic Subsequence
题目Given a string s, find the longest palindromic subsequence’s length in s.A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.Example 1:Input: s = “原创 2021-11-30 23:22:59 · 112 阅读 · 0 评论 -
LeetCode | 500. Keyboard Row
题目Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.In the American keyboard:the first row consists of the characters “qwertyuiop”,the second row原创 2021-11-30 23:19:01 · 150 阅读 · 0 评论 -
LeetCode | 494. Target Sum
题目ou are given an integer array nums and an integer target.You want to build an expression out of nums by adding one of the symbols ‘+’ and ‘-’ before each integer in nums and then concatenate all the integers.For example, if nums = [2, 1], you can add原创 2021-11-30 23:15:27 · 116 阅读 · 0 评论 -
LeetCode | 477. Total Hamming Distance
题目The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given an integer array nums, return the sum of Hamming distances between all the pairs of the integers in nums.Example 1:Input: nums =原创 2021-11-30 23:12:04 · 216 阅读 · 0 评论 -
LeetCode | 476. Number Complement
题目The complement of an integer is the integer you get when you flip all the 0’s to 1’s and all the 1’s to 0’s in its binary representation.For example, The integer 5 is “101” in binary and its complement is “010” which is the integer 2.Given an integer原创 2021-11-30 23:09:15 · 111 阅读 · 0 评论 -
LeetCode | 461. Hamming Distance
题目The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, return the Hamming distance between them.Example 1:Input: x = 1, y = 4Output: 2Explanation:1 (0 0 0 1)原创 2021-11-30 23:05:53 · 115 阅读 · 0 评论 -
LeetCode | 522. Longest Uncommon Subsequence II
题目Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.Return the sorted string. If there are multiple answers, return any of them.Example 1:原创 2021-11-30 23:03:20 · 98 阅读 · 0 评论 -
LeetCode | 522. Longest Uncommon Subsequence II
题目Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.Return the sorted string. If there are multiple answers, return any of them.Example 1:原创 2021-11-30 23:03:20 · 98 阅读 · 0 评论 -
LeetCode | 445. Add Two Numbers II
题目You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.You may assume the two numb原创 2021-11-30 22:59:53 · 541 阅读 · 0 评论 -
LeetCode | 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 o原创 2021-10-31 17:50:40 · 116 阅读 · 0 评论