DMITRII’s Substack

Share this post

Leetcode daily # 3.05.2023

dmitriisamoilenko.substack.com

Leetcode daily # 3.05.2023

[2215. Find the Difference of Two Arrays]

DMITRII SAMOILENKO
May 3, 2023
Share
Share this post

Leetcode daily # 3.05.2023

dmitriisamoilenko.substack.com

3.05.2023

2215. Find the Difference of Two Arrays easy

fun findDifference(nums1: IntArray, nums2: IntArray): List<List<Int>> = listOf(
    nums1.subtract(nums2.toSet()).toList(),
    nums2.subtract(nums1.toSet()).toList()
    )

blog post

Thanks for reading DMITRII’s Substack! Subscribe for free to receive new posts and support my work.

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/201

Intuition

Just do what is asked.

Approach

One way is to use two Sets and just filter them.
Another is to use intersect and distinct.
Third option is to sort both of them and iterate, that will use O(1) extra memory, but O(nlogn) time.

Complexity

  • Time complexity:
    O(n)

  • Space complexity:
    O(n)

Thanks for reading DMITRII’s Substack! Subscribe for free to receive new posts and support my work.

Share
Share this post

Leetcode daily # 3.05.2023

dmitriisamoilenko.substack.com
Previous
Next
Comments
Top
New

No posts

Ready for more?

© 2023 DMITRII SAMOILENKO
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing