【Leetcode】python - [349] Intersection of Two Arrays 個人解法筆記

整理 LeetCode #349 Intersection of Two Arrays — set 交集。

題目出處

349. Intersection of Two Arrays

難度

Easy

題目分類

Array, Hash Table, Two Pointers, Binary Search, Sorting

2022-05-12 一刷

個人範例程式碼

class Solution:
    def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
        return list(set(nums1) & set(nums2))

最近在練習程式碼本身就可以自解釋的 Coding style,可以嘗試直接閱讀程式碼理解

算法說明

一個 set and 就結束了…
好舒服的 easy 題目…

input handling

set and 的過程會幫我們處理掉

Boundary conditions

x

Reference

Licensed under CC BY-NC-SA 4.0
最後更新 May 12, 2022
使用 Hugo 建立
主題 StackJimmy 設計