当前位置:网站首页>哈希表卡片
哈希表卡片
2022-08-09 13:10:00 【花椒酱不吃花椒喵】
dict的各种函数
dict.get(key,defaultvalue)
class Solution(object):
def intersect(self, nums1, nums2):
counts = {
}
res = []
for num in nums1:
counts[num] = counts.get(num, 0) + 1
for num in nums2:
if num in counts and counts[num] > 0:
res.append(num)
counts[num] -= 1
return res
其他函数
enumerate遍历list的索引和值
zip同时遍历list或dict
e.g.:zip(dict1.values(),dict2.values())
s.find(x)找到数组s中值为x的索引,s.rfind(x)在数组中找到最后一个值为x的索引
class Solution:
def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]:
Aindex = {
u: i for i, u in enumerate(list1)}
best, ans = 1e9, []
for j, v in enumerate(list2):
i = Aindex.get(v, 1e9)
if i + j < best:
best = i + j
ans = [v]
elif i + j == best:
ans.append(v)
return ans
边栏推荐
- Professor Chen Qiang's "Machine Learning and R Application" course Chapter 14 Assignment
- 面试攻略系列(二)-- 秒杀系统
- RobotFramework 之 数据驱动
- 01_iTween_第一天--小球抛物线
- pytest 之 fixture的定义及作用域
- 记录本项目中用到的系统调用与C库函数-2
- 43. The sword refers to Offer 1 ~ 1 the number of occurrences of n integers (recursive, mathematics)
- NC192 二叉树的后序遍历
- offset、client、scroll、window.pageYOffset比较
- X264性能优化
猜你喜欢

RobotFramework 之 条件判断

RobotFramework 之 库与关键字

七夕力扣刷不停,343. 整数拆分(剑指 Offer 14- I. 剪绳子、剑指 Offer 14- II. 剪绳子 II)

Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres

一篇ngork直接使用

GIN Bind mode to get parameters and form validation

快来扔鸡蛋。

目标检测类间不平衡问题

技嘉显卡 RGBFusion 不能调光解决方法

面试攻略系列(三)-- 高级开发工程师面试问些啥?
随机推荐
X264性能优化
万物皆可柯里化的 Ramda.js
Draw a histogram with plot_hist_numeric()
pyautogui的简单操作(1)
group by的工作原理和优化思路
搭建大型分布式服务(四)Docker搭建开发环境安装Mysql
FFmpeg multimedia file processing (the basic concept of ffmpeg processing stream data)
43. The sword refers to Offer 1 ~ 1 the number of occurrences of n integers (recursive, mathematics)
javscript基础易错点集合
eslint语法规则报错
pyhook3简单应用(1)--实现截图保存功能
vivo手机上的系统级消息推送平台的架构设计实践
RobotFramework 之 RF变量与标准库关键字使用
搭建大型分布式服务(二)搭建会员服务
RobotFramework 之 数据驱动
FFmpeg长时间无响应的解决方法
Microsoft 10/11 命令行打开系统设置页(WUAP,!WIN32)
NC53 删除链表的倒数第n个节点
01_iTween_第一天--小球抛物线
【面试高频题】可逐步优化的链表高频题