string res ="";for(PR pr : lst){ string s = pr.first;intcnt = pr.second;for(inti =0; i < cnt; i++){ res += s; } }if(res[0] =='0'){return"0"; }else{returnres; } } };
比如[2,3,4],3乘以2等于6大于4,不符合题目要求,就不需要比较2了。 publicintdominantIndex(int[] nums) {intmax =0, second =0,index=0;for(inti=0; i<nums.length; i++) {if(nums[i] > max) { second = max; max = nums[i];index= i; }elseif(nums[i] > second) { second = nums...
nums))temp.sort(key=cmp_to_key(lambdax,y:int(x+y)-int(y+x)),reverse=True)return''.join(tempiftemp[0]!='0'else'0')deflargestNumber(self,nums:List[int])->str:"""「插入排序」, 时间复杂度O(n^
In a given integer array nums, there is always exactly one largest element. Find whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, otherwise return -1. Example 1: Input: nums = [...
https://leetcode-cn.com/contest/biweekly-contest-48/problems/second-largest-digit-in-a-string/ 题意 简单问题,直接暴力即可。 思路 暴力统计 代码 class Solution { public: int secondHighest(string s) { set<char> cnt; for(auto c : s){ ...
struct Node { int first, second; Node(){} Node(int f, int s) { first = f; second = s; } bool operator < (const Node tmp) const { if (first != tmp.first) { return first > tmp.first; } else { return second > tmp.second; } } }; class MedianFinder { public: priority_qu...
You may assume the number of calls to update and sumRange function is distributed evenly. 【解答】写的代码看起来有点啰嗦,大致思路是线段树。也就是说,每个节点都存放一个 sum,这样在求一段区间的和的时候会比较快;而在更新某一个数的时候,也只需要更新整个树从上到下的一条路径即可。 代码语...
count of smaller number after self: merge sort can count the numbers to the right/left when merging misc largest number: Just sort. Use a_b and b_a to decide which comes at first wiggle sort: sort pair by pair wiggle sort II: Quick select algorithm to find the kth largest element in...
(int second = first + 1; second < n; ++second) { // 需要和上一次枚举的数不相同 if (second > first + 1 && nums[second] == nums[second - 1]) { continue; } // 需要保证 b 的指针在 c 的指针的左侧 while (second < third && nums[second] + nums[third] > target) { --third...
2045.Second-Minimum-Time-to-Reach-Destination (M+) 2101.Detonate-the-Maximum-Bombs (M+) 2258.Escape-the-Spreading-Fire (H+) 2290.Minimum-Obstacle-Removal-to-Reach-Corner (M+) 2493.Divide-Nodes-Into-the-Maximum-Number-of-Groups (H-) 2812.Find-the-Safest-Path-in-a-Grid (M+) Multi St...