avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

6293. Count the number of good array

  2024-01-01        
字数统计: 187字   |   阅读时长: 1min

At first glance, this question is a double pointer,But I am not familiar with the double pointer,Most of the time was wasted when you set up the framework。

This question is the third question of Zhou Sai,The first two questions were killed quickly,But because I slept,It’s only half an hour left when the computer is turned on。

always theredebug,Watch this afternoon0x3fSolution。There is a set of explanations of his sliding window algorithm and double pointer。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from collections import Counter
from itertools import count
from typing import List


class Solution:
def countGood(self, nums: List[int], k: int) -> int:
start = 0
tail = 0
flag = 0
if len(set(nums)) == 1:
if k > len(nums) * (len(nums)-1) // 2:
return 0
while start < len(nums) - 1:
x = Counter(nums[start:tail])
if len(x) >= k:
flag2 = 0
for j in x:
if x[j] >= k:
flag2 += 1
if flag2 >= k:
flag += 1
else:
for i in x:
if x[i] * (x[i] - 1) // 2 >= k:
flag += 1
if tail != len(nums):
tail += 1
else:
start += 1

return flag
  • Python
  • unsolved

扫一扫,分享到微信

微信分享二维码
538.Convert the binary search tree to cumulative tree
6275. Make all the minimum operations of all elements in the array II
目录
ahoh, this article has no catalog.

150 篇 | 131.7k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号