Explanation: The third maximum does not exist, so the maximum (2) is returned instead. Example 3: Input: [2, 2, 3, 1] Output: 1 Explanation: Note that the third maximum here means the third maximum distinct number. Both numbers with value 2 are both considered as second maximum. 题解...
classSolution {public:intthirdMax(vector<int>&nums) {longfirst = LONG_MIN, second = LONG_MIN, third =LONG_MIN;for(intnum : nums) {if(num >first) { third=second; second=first; first=num; }elseif(num > second && num <first) { third=second; second=num; }elseif(num > third && ...
// #414 Description: Third Maximum Number | LeetCode OJ 解法1:水题。 // Solution 1: Easy. 代码1 // Code 1 415 Add Strings // #415 高精度加法 描述:如题。 // #415 Description: Add Strings | LeetCode OJ 解法1:水题。 // Solution 1: Easy. 代码1 // Code 1 416 Partition Equal...
Third Maximum Number 0.347 简单 88 #228 Summary Ranges 0.517 中等 89 #485 Max Consecutive Ones 0.561 简单 90 #566 Reshape the Matrix 0.643 简单 91 #670 Maximum Swap 0.4 中等 92 #870 Advantage Shuffle 0.37 中等 93 #713 Subarray Product Less Than K 0.349 中等 94 #643 Maximum Average Subarr...
414 Third Maximum Number Algorithms Easy 413 Arithmetic Slices Algorithms Easy 412 Fizz Buzz Algorithms Easy 411 Minimum Unique Word Abbreviation Algorithms Medium 410 Split Array Largest Sum Algorithms Medium 409 Longest Palindrome Algorithms Easy 408 Valid Word Abbreviation Algorithms Easy 407 Trapping Rai...
给定整数数组nums和整数k,请返回数组中第k个最大的元素。 请注意,你需要找的是数组排序后的第k个最大的元素,而不是第k个不同的元素。 你必须设计并实现时间复杂度为O(n)的算法解决此问题。 示例1: 输入:[3,2,1,5,6,4],k = 2输出:5
No_0374_Guess Number Higher or Lower No_0376_Wiggle Subsequence No_0377_Combination Sum IV No_0383_Ransom Note No_0384_Shuffle an Array No_0387_First Unique Character in a String No_0389_Find the Difference No_0403_Frog Jump No_0404_Sum of Left Leaves No_0412_FizzBuzz No_0414_...
405 Convert a Number to Hexadecimal Easy JavaScript 406 Queue Reconstruction by Height Medium JavaScript Go 409 Longest Palindrome Easy JavaScript Python 412 Fizz Buzz Easy JavaScript 413 Arithmetic Slices Medium JavaScript 414 Third Maximum Number Easy Python 415 Add Strings Easy JavaScript 416 Partition...
{ continue; } // c 对应的指针初始指向数组的最右端 int third = n - 1; int target = -nums[first]; // 枚举 b for (int second = first + 1; second < n; ++second) { // 需要和上一次枚举的数不相同 if (second > first + 1 && nums[second] == nums[second - 1]) { continue;...
Split Array Largest Sum 412. Fizz Buzz 414. Third Maximum Number 416. Partition Equal Subset Sum 421. Maximum XOR of Two Numbers in an Array 424. Longest Repeating Character Replacement 433. Minimum Genetic Mutation 435. Non-overlapping Intervals 436. Find Right Interval 437. Path Sum III 438...