Notice thatxdoes not have to be an element innums. Returnxif the array is special, otherwise, return-1. It can be proven that ifnumsis special, the value forxis unique. Example 1: Input: nums = [3,5] Output: 2 Explanation: There are 2 values (3 and 5) that are greater than ...
classSolution:defspecialArray(self,nums:List[int])->int:forx inrange(len(nums)+1):count=0fori in nums:ifi>=x:count+=1ifcount>x:breakifcount==x:returnxreturn-1
Asubsequenceof an array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements. Two subsequences aredifferentif theset of indiceschosen are different. Example 1: Input:nums = [0,1,2,2]Output:3Explanation:The sp...
题目地址:https://leetcode.com/problems/groups-of-special-equivalent-strings/description/题目描述:You are given an array A of strings.Two strings S and T are special-equivalent if after any number of moves, S == T.A move consists of choosing two indices i and j with i % 2 == j % ...
[leetcode] 1475. Final Prices With a Special Discount in a Shop 技术标签: python leetcode题解Description Given the array prices where prices[i] is the price of the ith item in a shop. There is a special discount for items in the shop, if you buy the ith item, then you will ...
[leetcode] 893. Groups of Special-Equivalent Strings Description You are given an array A of strings. A move onto S consists of swapping any two even indexed characters of S, or any two odd indexed characters of S. Two strings S and T are special-equivalent if after any number of ...
classSolution(object):defmyPow(self,x,n):""" :type x: float :type n: int :rtype: float """ifn==0:return1ifn<0:res=self.myPow(x,-n)return1.0/res temp=self.myPow(x,n/2)ifn%2:returntemp*temp*xelse:returntemp*tempdefmyPow(self,x,n):""" ...
For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1] has the largest sum = 6. my answer: classSolution(object):defmaxSubArray(self,nums):""" :type nums: List[int] :rtype: int
classSolution {public:intspecialArray(vector<int>&nums) { sort(nums.begin(),nums.end());intstart =0, end = nums.size()-1;while(start <end){intmid = start + (end - start) /2;if(nums.size()-mid <= nums[mid]) end = mid;//二分法,重点在这个等号elsestart = mid+1; ...
classSolution{public:stringprocess(string& s){ string even ="", odd ="";intsz = s.size();for(inti =0; i < sz; i +=2){ even += s[i]; }for(inti =1; i < sz; i +=2){ odd += s[i]; }sort(even.begin(), even.end());sort(odd.begin(), odd.end());returneven +...