leetcode 485[easy]---Max Consecutive Ones Givenabinaryarray, findthemaximumnumberofconsecutive 1sinthisarray.Example 1: Note:Theinputarraywill only contain 0 and 1.Thelengthofinputarrayisapositive integer and willnot 作业(十二)——414. Third Maximum Number ...
``` 输入:root = [4,1,3,null,null,2], val = 5 输出:[5,4,null,1,3,null,null,2] 解释:A = [1,4,2,3], B = [1,4,2,3,5] ``` 示例2: ``` 输入:root = [5,2,4,null,1], val = 3 输出:[5,2,4,null,1,null,3] 解释:A = [2,1,5,4], B = [2,1,5,4,3...
1849-splitting-a-string-into-descending-consecutive-values.cpp 1851-Minimum-Interval-To-Include-Each-Query.cpp 1851-minimum-interval-to-include-each-query.cpp 1899-merge-triplets-to-form-target-triplet.cpp 1905-count-sub-islands.cpp 1911-maximum-alternating-subsequence-sum.cpp 1920-build-array-from...
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1: Input: [3, 2, 1] Output: 1 Explanation: The third maximum is 1. Example 2: Input: [1, 2] Out...
1849-splitting-a-string-into-descending-consecutive-values.cpp 1851-Minimum-Interval-To-Include-Each-Query.cpp 1851-minimum-interval-to-include-each-query.cpp 1899-merge-triplets-to-form-target-triplet.cpp 1905-count-sub-islands.cpp 1911-maximum-alternating-subsequence-sum.cpp 1920-build-array-from...
My Leetcode Solutions. Contribute to developer-kush/Leetcode development by creating an account on GitHub.
any two numbers that are in the same bucket cannot be the answer. Thus, we only need to store the largest number and the smallest number in each bucket. Then, we can scan the buckets sequentially and get a sorted list. The maximum difference between two consecutive elements is the answer...
Multiplication of any three numbers in the input won't exceed the range of 32-bit signed integer. 找出3个数,使他们的乘积最大,数字会有负数 C++(79ms): 1classSolution {2public:3intmaximumProduct(vector<int>&nums) {4sort(nums.begin(),nums.end()) ;5intlen =nums.size() ;6inta = nums...
https://discuss.leetcode.com/topic/63903/short-easy-c-using-set classSolution{public:intthirdMax(vector<int>& nums){ set<int>top3;for(intnum : nums){ top3.insert(num);if(top3.size() >3)top3.erase(top3.begin()); }returntop3.size() ==3? *top3.begin() : *top3.rbegin();...