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

1604Warn alert person who uses the same employee card within one hour One question daily

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

topic

2023-02-08.png

Thought:

Pay attention to the data pre -processing of this time question,You can convert time to minutes,You can look at the notes in the code。Thought andylbThe consistency of the big man。
Pay attention to,In fact, use the order directlysortIt’s okay。
python: :=Walrus operator,Can be assigned in judgment
Golang: SScanfSscanfStringstrScanning text,according toformat The format specified by the parameter will save the values ​​of the blank separation that is successfully read in the parameters that successfully passed to the function of this function。
Back to the number of entries for successful scanning and any error encountered。

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution:
def alertNames(self, keyName: List[str], keyTime: List[str]) -> List[str]:
ans = set()
dict1 = defaultdict(list)
for name, time in zip(keyName, keyTime):
dict1[name].append(int(time[:2])*60+int(time[3:]))
print(dict1)
for i in dict1:
# definition10:00-11:00Three counts appear,Warn
if len(dict1[i]) >= 3:
dict1[i].sort()
print(dict1[i])
for j in range(len(dict1[i])):
# Traversing the current hour to one hour,It seems to be able to watch the slice directly
# for k in range(len(dict1[i]) + 1, len(dict1[i])+3):
if j + 2 < len(dict1[i]):
# if dict1[i][j:j + 3][0].replace(":", "")[:2]
if abs(dict1[i][j:j + 3][-1] -
dict1[i][j:j + 3][0]) <= 60:
ans.add(i)
print(dict1[i][j:j + 3])
ans = list(ans)
ans.sort()
return ans
  • Python
  • answer
  • Hash table

扫一扫,分享到微信

微信分享二维码
1551. Make all the minimum operations of all elements in the array
1653. The minimum number of times to balance the string balance
目录
  1. 1. topic
  2. 2. Thought:
  3. 3. Code:

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