- 博客(93)
- 收藏
- 关注
原创 Leetcode 29. Divide Two Integers (Python)
Given two integers and , divide two integers without using multiplication, division, and mod operator.The integer division should truncate toward zero, which means losing its fractional part. For example, would be truncated to , and would be truncated t
2022-07-02 13:50:15
973
原创 Leetcode 215. Kth Largest Element in an Array (Python)
Given an integer array and an integer , return the largest element in the array.Note that it is the largest element in the sorted order, not the distinct element.Example 1:Input: nums = [3,2,1,5,6,4], k = 2Output: 5Example 2:Input: nums = [3,2,3,
2022-07-02 13:48:51
724
原创 Leetcode 151. Reverse Words in a String (Python)
Given an input string , reverse the order of the words.A word is defined as a sequence of non-space characters. The words in will be separated by at least one space.Return a string of the words in reverse order concatenated by a single space.Note that ma
2022-07-02 13:47:25
886
原创 Leetcode 128. Longest Consecutive Sequence (Python)
Given an unsorted array of integers , return the length of the longest consecutive elements sequence.You must write an algorithm that runs in time.Example 1:Input: nums = [100,4,200,1,3,2]Output: 4Explanation: The longest consecutive elements sequence
2022-07-02 13:46:24
709
原创 Leetcode 77. Combinations (Python)
Given two integers and , return all possible combinations of numbers out of the range .You may return the answer in any order.Example 1:Input: n = 4, k = 2Output:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]Example 2:Input: n = 1, k =
2022-07-02 13:44:02
655
原创 Leetcode 90. Subsets II (Python)
Given an integer array that may contain duplicates, return all possible subsets (the power set).The solution set must not contain duplicate subsets. Return the solution in any order.Example 1:Input: nums = [1,2,2]Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
2022-07-02 13:42:53
757
原创 Leetcode 137. Single Number II (Python)
Given an integer array where every element appears three times except for one, which appears exactly once. Find the single element and return it.You must implement a solution with a linear runtime complexity and use only constant extra space.Example 1:In
2022-07-02 13:41:47
888
原创 Leetcode 78. Subsets (Python)
Given an integer array of unique elements, return all possible subsets (the power set).The solution set must not contain duplicate subsets. Return the solution in any order.Example 1:Input: nums = [1,2,3]Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]
2022-07-02 13:40:33
636
原创 Leetcode 43. Multiply Strings (Python)
Given two non-negative integers and represented as strings, return the product of and , also represented as a string.Note: You must not use any built-in BigInteger library or convert the inputs to integer directly.Example 1:Input: num1 = "2",
2022-07-02 13:38:17
582
原创 Leetcode 50. Pow(x, n) (Python)
Implement pow(x, n), which calculates raised to the power (i.e., ).Example 1:Input: x = 2.00000, n = 10Output: 1024.00000Example 2:Input: x = 2.10000, n = 3Output: 9.26100Example 3:Input: x = 2.00000, n = -2Output: 0.25000Explanation: 2-2 =
2022-07-02 13:34:25
177
原创 Leetcode 389. Find the Difference (Python)
You are given two strings and .String is generated by random shuffling string and then add one more letter at a random position.Return the letter that was added to .Example 1:Input: s = "abcd", t = "abcde"Output: "e"Expl
2022-06-30 15:34:29
222
原创 Leetcode 2239. Find Closest Number to Zero (Python)
Given an integer array of size , return the number with the value closest to in . If there are multiple answers, return the number with the largest value.Example 1:Input: nums = [-4,-2,1,4,8]Output: 1Explanation:The distance from -4 to 0 is |-4| = 4.
2022-06-30 15:32:30
346
原创 Leetcode 724. Find Pivot Index (Python)
Given an array of integers , calculate the pivot index of this array.The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.If the index is on the
2022-06-30 15:30:43
245
原创 Leetcode 94. Binary Tree Inorder Traversal (Python)
Given the of a binary tree, return the inorder traversal of its nodes' values.Example 1:Input: root = [1,null,2,3]Output: [1,3,2]Example 2:Input: root = []Output: []Example 3:Input: root = [1]Output: [1]Constraints:
2022-06-30 15:29:15
143
原创 Leetcode 21. Merge Two Sorted Lists (Python)
You are given the heads of two sorted linked lists and .Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists.Return the head of the merged linked list.Example 1:Input: list1 = [1,2,4], li
2022-06-30 15:27:25
304
原创 Leetcode 387. First Unique Character in a String(Python)
Given a string , find the first non-repeating character in it and return its index. If it does not exist, return .Example 1:Input: s = "leetcode"Output: 0Example 2:Input: s = "loveleetcode"Output: 2Example 3:Input: s = "
2022-06-30 15:25:32
117
原创 Leetcode 867. Transpose Matrix (python)
Given a 2D integer array , return the transpose of .The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices.Example 1:Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]Output: [[1,4,7],[2,5,8],[3,6,9]]
2022-06-30 15:23:45
107
原创 1480. Running Sum of 1d Array (Java)
Given an array . We define a running sum of an array as .Return the running sum of .Example 1:Input: nums = [1,2,3,4]Output: [1,3,6,10]Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].Example 2:Input: nums = [1,1,1,1,1]Outpu
2022-06-30 15:19:56
159
原创 1480. Running Sum of 1d Array (Python)
Given an array . We define a running sum of an array as .Return the running sum of .Example 1:Input: nums = [1,2,3,4]Output: [1,3,6,10]Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].Example 2:Input: nums = [1,1,1,1,1]Outpu
2022-06-30 15:15:57
181
原创 3. Longest Substring Without Repeating Characters (python)
Given a string , find the length of the longest substring without repeating characters.Example 1:Input: s = "abcabcbb"Output: 3Explanation: The answer is "abc", with the length of 3.Example 2:Input: s = "bbbbb"Output:
2022-06-30 15:14:30
197
原创 Leetcode 242. Valid Anagram (Python)
Given two stringssandt, returntrueiftis an anagram ofs, andfalseotherwise.AnAnagramis a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.Example 1:Inp...
2022-05-28 14:14:49
188
原创 Leetcode 268. Missing Number (Python)
Given an arraynumscontainingndistinct numbers in the range[0, n], returnthe only number in the range that is missing from the array.Example 1:Input: nums = [3,0,1]Output: 2Explanation: n = 3 since there are 3 numbers, so all numbers are in t...
2022-05-28 13:30:50
210
原创 Leetcode 338. Counting Bits (Python)
Given an integern, returnan arrayansof lengthn + 1such that for eachi(0 <= i <= n),ans[i]is thenumber of1'sin the binary representation ofi.Example 1:Input: n = 2Output: [0,1,1]Explanation:0 --> 01 --> 12 --> 10E...
2022-05-28 13:29:42
242
原创 Leetcode 1342. Number of Steps to Reduce a Number to Zero (Java)
Given an integernum, returnthe number of steps to reduce it to zero.In one step, if the current number is even, you have to divide it by2, otherwise, you have to subtract1from it.Example 1:Input: num = 14Output: 6Explanation:Step 1) 14 is...
2022-05-28 13:28:20
122
原创 Leetcode 1342. Number of Steps to Reduce a Number to Zero (Python)
Given an integernum, returnthe number of steps to reduce it to zero.In one step, if the current number is even, you have to divide it by2, otherwise, you have to subtract1from it.Example 1:Input: num = 14Output: 6Explanation:Step 1) 14 is...
2022-05-28 13:27:16
146
原创 Leetcode 190. Reverse Bits (Python)
Reverse bits of a given 32 bits unsigned integer.Note:Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation,
2022-05-28 13:25:25
154
原创 Leetcode 412. Fizz Buzz (Python)
Given an integern, returna string arrayanswer(1-indexed) where:answer[i] == "FizzBuzz"ifiis divisible by3and5. answer[i] == "Fizz"ifiis divisible by3. answer[i] == "Buzz"ifiis divisible by5. answer[i] == i(as a string) if none of th...
2022-05-28 13:23:32
354
原创 Leetcode 191. Number of 1 Bits (Python)
Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as theHamming weight).Note:Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a s.
2022-05-28 13:22:09
152
原创 Leetcode 326. Power of Three (Python)
Given an integern, returntrueif it is a power of three. Otherwise, returnfalse.An integernis a power of three, if there exists an integerxsuch thatn == 3x.Example 1:Input: n = 27Output: trueExample 2:Input: n = 0Output: falseEx...
2022-04-28 10:41:39
861
原创 342. Power of Four (Python)
Given an integern, returntrueif it is a power of four. Otherwise, returnfalse.An integernis a power of four, if there exists an integerxsuch thatn == 4x.Example 1:Input: n = 16Output: trueExample 2:Input: n = 5Output: falseExam...
2022-04-28 10:40:38
762
原创 Leetcode 258. Add Digits (Python)
Given an integernum, repeatedly add all its digits until the result has only one digit, and return it.Example 1:Input: num = 38Output: 2Explanation: The process is38 --> 3 + 8 --> 1111 --> 1 + 1 --> 2 Since 2 has only one digit, re.
2022-04-28 10:39:31
787
原创 Leetcode 53. Maximum Subarray
Given an integer arraynums, find the contiguous subarray (containing at least one number) which has the largest sum and returnits sum.Asubarrayis acontiguouspart of an array.Example 1:Input: nums = [-2,1,-3,4,-1,2,1,-5,4]Output: 6Explanati...
2022-04-21 16:51:51
344
原创 Leetcode 231. Power of Two (Python)
Given an integern, returntrueif it is a power of two. Otherwise, returnfalse.An integernis a power of two, if there exists an integerxsuch thatn == 2x.Example 1:Input: n = 1Output: trueExplanation: 20 = 1Example 2:Input: n = 16Ou...
2022-04-16 15:10:13
698
原创 Leetcode 169. Majority Element (Python)
Given an arraynumsof sizen, returnthe majority element.The majority element is the element that appears more than⌊n / 2⌋times. You may assume that the majority element always exists in the array.Example 1:Input: nums = [3,2,3]Output: 3Ex...
2022-04-16 14:23:13
789
原创 Leetcode 2236. Root Equals Sum of Children (Python)
You are given therootof abinary treethat consists of exactly3nodes: the root, its left child, and its right child.Returntrueif the value of the root is equal to thesumof the values of its two children, orfalseotherwise.Example 1:Inpu...
2022-04-13 10:14:39
786
原创 Leetcode 2235. Add Two Integers (Python)最简单的题
Given two integersnum1andnum2, returnthesumof the two integers.Example 1:Input: num1 = 12, num2 = 5Output: 17Explanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.Example 2:Input: num1 = -10, num2 = 4Outp...
2022-04-13 10:13:08
968
原创 Leetcode 283. Move Zeroes (Python)
Given an integer arraynums, move all0's to the end of it while maintaining the relative order of the non-zero elements.Notethat you must do this in-place without making a copy of the array.Example 1:Input: nums = [0,1,0,3,12]Output: [1,3,12,0,...
2022-04-13 10:09:51
515
原创 Leetcode 191. Number of 1 Bits (Python)
Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as theHamming weight).Note:Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a s.
2022-04-12 15:27:19
492
原创 Leetcode 67. Add Binary (Python)
Given two binary stringsaandb, returntheir sum as a binary string.Example 1:Input: a = "11", b = "1"Output: "100"Example 2:Input: a = "1010", b = "1011"Output: "10101"Constraints:1 <= a.length, b.length <= 104 aandbconsi...
2022-04-09 11:43:16
886
原创 Leetcode 414. Third Maximum Number
Given an integer arraynums, returnthethird distinct maximumnumber in this array. If the third maximum does not exist, return themaximumnumber.Example 1:Input: nums = [3,2,1]Output: 1Explanation:The first distinct maximum is 3.The second di...
2022-04-08 15:39:23
196
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人