当前位置:网站首页>[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
边栏推荐
- Digital stopwatch based on Verilog HDL
- QT | event system qevent
- Simple operation K6
- C language: deep analysis function stack frame
- Let me introduce you to the partition automatic management of data warehouse
- How to make five kinds of data structures in redis
- 每周小结(*66):下一个五年
- Implement a avatar looping control
- Restructuredtext grammar summary for beginners
- [Nuxt 3] (十)运行时配置
猜你喜欢

JS ------ Chapter II JS logic control

每周小结(*66):下一个五年

Branch and loop statements in C language learning

2022 最 NB 的 JVM 基础到调优笔记, 吃透阿里 P6 小 case

Implement a avatar looping control

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

【无标题】

Coding builds an image, inherits the self built basic image, and reports an error unauthorized: invalid credential Please confirm that you have entered the correct user name and password.

Opengauss kernel analysis: query rewriting

Salesforce zero foundation learning (116) workflow - & gt; On flow
随机推荐
Be an artistic test / development programmer and slowly change yourself
[brother hero July training] day 20: search Binary Tree
Mandatory interview questions: 1. shallow copy and deep copy_ Shallow copy
.net redis client newlife.redis.core library usage
Architecture design of multi live shopping mall
[acwing周赛复盘] 第 61 场周赛20220723
Qt学习-利用数据库单例完成 登录匹配 + 注册 功能实现
Notes of Teacher Li Hongyi's 2020 in-depth learning series 5
Go基础笔记_4_map
云计算三类巨头:IaaS、PaaS、SaaS,分别是什么意思,应用场景是什么?
What are the meanings and application scenarios of the three giants of cloud computing: IAAs, PAAS and SaaS?
SQL result export function. If you click the work order but don't enter it, the interface is always blank and there is no response. What should you do?
Simple message queue implementation nodejs + redis =mq
Restructuredtext grammar summary for beginners
Sql文件导入数据库-保姆级教程
Excel文件处理工具类(基于EasyExcel)
Analysis of WPF multi finger application development
MySQL common basic commands
BGP related knowledge points
每周小结(*66):下一个五年