当前位置:网站首页>[leetcode weekly replay] 303rd weekly 20220724
[leetcode weekly replay] 303rd weekly 20220724
2022-07-25 00:02:00 【Seven water Shuliang】
[LeetCode Weekly replay ] The first 303 Weekly match 20220724
One 、 Summary of this week's race
- A week of losing points .
- The first three questions are hard to do very quickly , Question 4: sitting and wearing at the bottom of the prison .

Two 、 [Easy] 6124. The first letter that appears twice
link : 6124. The first letter that appears twice
1. Title Description

2. Thought analysis
grading Easy.
According to the meaning of the question .
3. Code implementation
class Solution:
def repeatedCharacter(self, s: str) -> str:
cnt = defaultdict(int)
for c in s:
cnt[c]+= 1
if cnt[c] == 2:
return c
3、 ... and 、[Medium] 6125. Equal row and column pairs
link : 6125. Equal row and column pairs
1. Title Description

2. Thought analysis
grading Medium.
Violent judgment after transposition .
3. Code implementation
class Solution:
def equalPairs(self, grid: List[List[int]]) -> int:
n = len(grid)
g = [[0]*n for i in range(n)]
for i in range(n):
for j in range(n):
g[j][i] = grid[i][j]
ans = 0
for i in range(n):
for j in range(n):
if g[i] == grid[j]:
ans += 1
return ans
Four 、[Medium] 6092. Replace elements in an array
link : 6092. Replace elements in an array
1. Title Description

2. Thought analysis
grading Medium.
And the biweekly match last night T3 almost , Namely k,v Mutual hash of .
3. Code implementation
class FoodRatings:
def __init__(self, foods: List[str], cuisines: List[str], ratings: List[int]):
self.f_c = defaultdict()
self.f_r = defaultdict()
from sortedcontainers import SortedList
self.c_rf = defaultdict(SortedList)
c_rf = self.c_rf
f_c = self.f_c
f_r = self.f_r
n = len(foods)
for f,c,r in zip(foods,cuisines,ratings):
c_rf[c].add((-r,f))
f_c[f] = c
f_r[f] = r
def changeRating(self, food: str, newRating: int) -> None:
c_rf = self.c_rf
f_c = self.f_c
f_r = self.f_r
f = food
c = f_c[food]
r = f_r[food]
c_rf[c].remove((-r,f))
r = newRating
c_rf[c].add((-r,f))
f_c[f] = c
f_r[f] = newRating
# print(c_rf)
def highestRated(self, cuisine: str) -> str:
return self.c_rf[cuisine][0][1]
# Your FoodRatings object will be instantiated and called as such:
# obj = FoodRatings(foods, cuisines, ratings)
# obj.changeRating(food,newRating)
# param_2 = obj.highestRated(cuisine)
5、 ... and 、[Hard] 6127. The number of high-quality pairs
link : 6127. The number of high-quality pairs
1. Title Description

2. Thought analysis
grading Hard.
Be in jail .
- Actually found a&b and a|b Bit 1 Sum of numbers =a The number of +b The number of .
- So count the bits of each number 1 Number , The sum calculated after sorting is greater than k Logarithm of .
3. Code implementation
class Solution:
def countExcellentPairs(self, nums: List[int], k: int) -> int:
""" 001 010 011 001 101 001 001 """
nums = sorted(list(set(nums)))
def hammingWeight( n: int) -> int:
ret = 0
while n:
n &= n - 1
ret += 1
return ret
arr = []
for a in nums:
arr.append(hammingWeight(a))
arr.sort()
n = len(arr)
ans = 0
for i,a in enumerate(arr):
j = bisect_left(arr,k-a)
ans += n-j
return ans
边栏推荐
- Notes of Teacher Li Hongyi's 2020 in-depth learning series 3
- Notes of Teacher Li Hongyi's 2020 in-depth learning series 9
- Analysis of WPF multi finger application development
- Leetcode 0123. the best time to buy and sell stocks III: dynamic programming + simulation in constant space
- With screen and nohup running, there is no need to worry about deep learning code anymore | exiting the terminal will not affect the operation of server program code
- 线段树杂谈
- 剖析kubernetes集群内部DNS解析原理
- What are the meanings and application scenarios of the three giants of cloud computing: IAAs, PAAS and SaaS?
- First experience of flask
- Modify the existing annotator name in the word document
猜你喜欢

C language: deep analysis function stack frame

数组中只出现一次的两个数字
![[英雄星球七月集训LeetCode解题日报] 第24日 线段树](/img/ae/1f3288a99cb07fcbb1836357e0229a.png)
[英雄星球七月集训LeetCode解题日报] 第24日 线段树

Notes of Teacher Li Hongyi's 2020 in-depth learning series 3

50 places are limited to open | with the news of oceanbase's annual press conference coming!

Go基础笔记_4_map

Grafana - influxdb visual K6 output

91. (leaflet chapter) leaflet situation plotting - offensive direction drawing

Leetcode 1260. two dimensional grid migration: two solutions (k simulations / one step)

UART
随机推荐
codeforces round #797 ABCDEFG
Optaplanner will abandon DRL (drools) scoring method!!!
Install software on kubernetes cluster using helm 3 package manager
How painful is it to write unit tests? Can you do it
Notes of Teacher Li Hongyi's 2020 in-depth learning series 6
JS ------ Chapter II JS logic control
Notes of Teacher Li Hongyi's 2020 in-depth learning series 8
cloud chart
Notes of Teacher Li Hongyi's 2020 in-depth learning series 5
Add a little surprise to life and be a prototype designer of creative life -- sharing with X contestants in the programming challenge
痞子衡嵌入式:MCUXpresso IDE下将源码制作成Lib库方法及其与IAR,MDK差异
Remember the problem of using redisson to step on the pit once
BGP related knowledge points
Use es to realize fuzzy search and search recommendation of personal blog
Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK
C language program environment and preprocessing
Be an artistic test / development programmer and slowly change yourself
JS ------ Chapter 3 JS cycle
Simple operation K6
Discussion on line segment tree