当前位置: 首页 > news >正文

Python | Leetcode Python题解之第350题两个数组的交集II

题目:

题解:

class Solution:def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:nums1.sort()nums2.sort()length1, length2 = len(nums1), len(nums2)intersection = list()index1 = index2 = 0while index1 < length1 and index2 < length2:if nums1[index1] < nums2[index2]:index1 += 1elif nums1[index1] > nums2[index2]:index2 += 1else:intersection.append(nums1[index1])index1 += 1index2 += 1return intersection

http://www.mrgr.cn/news/1074.html

相关文章:

  • C# 中 Grpc服务端调用客户端方法
  • SQL-约束篇
  • Git入门 -- 区域详解
  • 《第十九章 多媒体 - 摄像头与相册》
  • 【信创】双系统下删除Windows只保留麒麟系统
  • 如何优雅的薅羊毛之Flux.1免费使用还支持中文prompt
  • 01_React简介、基础入门
  • OpenTelemetry:新一代的开源可观测性标准
  • Redis在Linux(Centos7)单机部署和集群部署
  • 【中等】 猿人学web第一届 第7题 动态字体,随风漂移
  • 华为 OLT 添加 ONT 配置 (OMCI 管理模式)
  • 清理 Conda 缓存和 Pip 缓存
  • 【hot100篇-python刷题记录】【矩阵置零】
  • 零基础学习Redis(5) -- redis单线程模型介绍
  • 第一篇:fiddler学习日记配置抓取https和http
  • 二:《Python基础语法汇总》— 条件判断与循环结构
  • 模电实验4 - 单电源直接耦合放大电路
  • 【Qt】Qt窗口 | QDockWidget 浮动窗口
  • python使用flask实现自动根据url寻找对应目录/文件/方法,实现动态路由
  • xss GAME (xss漏洞攻击1-8)