0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

NeetCode ContainsDuplicate

0
Posted at

はじめに

転職の内定が決まった。
しかし、ある会社でコーディングテストがあったが
全く歯が立たんかった。
克服したいので、NeetCodeを少しずつ進めていく。
ひとまずEasyのものから。
その際の回答に必要だった知識や気づきを書いていこうと思う。

挑戦した問題

問題の概要

Given an integer array nums, return true if any value appears more than once in the array, otherwise return false.

Example

Input: nums = [1, 2, 3, 3]

Output: true

回答の流れ

  • 空のHashSetを作成
  • foreachでnumsを回す
    • HashSetにある:return true
    • HashSetにない: add num
  • Loop後:return false

回答のために必要だった知識

// HashSet<T>は重複を許さない<T>の配列
HashSet<int> seen = new HashSet<int>();
// Contain=リストに入っているかどうかをチェックする
if (seen.Contains(num))
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?