Returnthe number of nice pairs of indices. Since that number can be too large, return itmodulo109+ 7. Example 1: Input:nums = [42,11,1,97]Output:2Explanation:The two pairs are: - (0,3) : 42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121. ...
Can you solve this real interview question? Count Number of Nice Subarrays - Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays. Example 1:
In this, i will post my solutions of POTD's of Leetcode - Leetcode/2057-count-salary-categories/2057-count-salary-categories.sql at main · raghav161/Leetcode
1 <= k <= nums.length 这道题给了一个数组 nums,和一个正整数k,定义了一种 nice 子数组,即子数组中有k个奇数,现在问有多少个 nice 子数组。由于求的是子数组,所以必须是连续的,而如果把每个子数组当作一个窗口的话,就不难想到可以用滑动窗口 Sliding Window 来做,LeetCode 中使用滑动窗口的题目还挺多...
classSolution{public:longlongrev(longlongx){longlongres=0;while(x) { res=res*10+x%10; x/=10; }returnres; }longlongc(longlongx){return(x*(x-1))/2; }intcountNicePairs(vector<int>& nums){longlongres=0;vector<longlong>sup(nums.size()); ...
Your LeetCode username gautan74 Category of the bug [ X ] Question [ X ] Solution Language Missing Test Cases Description of the bug Receiving Run Time Error ''' Line 1034: Char 34: runtime error: addition of unsigned offset to 0x6030000...
由于奇数和奇数间存在偶数,所以一定存在其他子数组 [l,r] 满足[l,r] 包含[odd[i],odd[i+k−1]] 且[l,r] 里的奇数个数为 k 个,那么这个需要怎么统计呢?由于我们已经记录了每个奇数的下标,所以我们知道对于第 i 个奇数,它的前一个奇数的下标为 odd[i−1],也就是说 (odd[i−1],odd[i]) ...
clean codeMap<String, Integer>wordMap=newHashMap<>();// Using try-with-resource statement for automatic resource managementtry(FileInputStreamfis=newFileInputStream(fileName);DataInputStreamdis=newDataInputStream(fis);BufferedReaderbr=newBufferedReader(newInputStreamReader(dis))) {// words are ...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays. Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1...
题目如下: Given an array of integersnumsand an integerk. Asubarray is called nice if there arekodd numbers on it. Return the number of nice sub-arrays. Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,...