A subarrayarrisgoodif there areat leastkpairs of indices(i, j)such thati < jandarr[i] == arr[j]. Asubarrayis a contiguousnon-emptysequence of elements within an array. Example 1: Input:nums = [1,1,1,1,1], k = 10Output:1Explanation:The only good subarray is the array nums its...
1730-special-array-with-x-elements-greater-than-or-equal-x 1734-bank-account-summary-ii 1744-number-of-ways-to-form-a-target-string-given-a-dictionary 1755-defuse-the-bomb 1764-maximum-repeating-substring 1765-merge-in-between-linked-lists 1767-design-front-middle-back-queue 1775-design-an-o...
Given a strings, returnthe number of substrings that have only one distinct letter. Example 1: Input: s = "aaaba" Output: 8 Explanation: The substrings with one distinct letter are "aaa", "aa", "a", "b". "aaa" occurs 1 time. "aa" occurs 2 times. "a" occurs 4 times. "b" ...
题目地址:https://leetcode-cn.com/problems/count-substrings-with-only-one-distinct-letter/ 题目描述 Given a string S, return the number of substrings that have only one distinct letter. Example 1: Input: S = "aaaba" Output: 8 Explanation: The substrings with one distinct l...
1classSolution {2func countLetters(_ S: String) ->Int {3vararr:[Character] =Array(S)4arr.append("#")5vark:Int =06varc:Character ="#"7varans:Int =08foriin0..<arr.count9{10ifarr[i] ==c11{12k +=113}14else15{16ifc !="#"17{18ans += k * (k +1) /219}20c =arr[i]21...
0186-Reverse-Words-in-a-String-II 0188-Best-Time-to-Buy-and-Sell-Stock-IV 0189-Rotate-Array 0191-Number-of-1-Bits 0198-House-Robber 0200-Number-of-Islands 0202-Happy-Number 0203-Remove-Linked-List-Elements 0205-Isomorphic-Strings 0206-Reverse-Linked-List 0207-Course-Sch...
It can be proven that there are no more than 3 square-free subsets in the given array. Example 2: Input:nums = [1]Output:1Explanation:There is 1 square-free subset in this example: - The subset consisting of the 0thelement [1]. The product of its elements is 1, which is a squar...
Given a stringS, return the number of substrings that have only one distinct letter. Example 1: Input: S = "aaaba" Output: 8 Explanation: The substrings with one distinct letter are "aaa", "aa", "a", "b". "aaa" occurs 1 time. ...