Le migliori 150 intervisteFacile

Contiene duplicato

Guida dettagliata e implementazione Python per il problema "Contiene duplicati".

Dichiarazione del problema

Facile

Dato un array di numeri interi nums, restituisce True se qualsiasi valore appare almeno due volte nell'array e restituisce False se ogni elemento è distinto.

Scrivi una funzione containsDuplicate(nums: List[int]) -> bool.

Vincoli
  • 1 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9

Esempi

Example 1
Input
nums = [1, 2, 3, 1]
Output
True
Explanation

The element 1 appears at index 0 and index 3, so there is a duplicate.

Example 2
Input
nums = [1, 2, 3, 4]
Output
False
Explanation

All elements are distinct.

Example 3
Input
nums = [1, 1, 1, 3, 3, 4, 3, 2, 4, 2]
Output
True
Explanation

Multiple elements repeat: 1, 3, 4, and 2.

Need a Hint?
Prendi in considerazione l'utilizzo di strutture dati specifiche per array e hashing come set o heap.
Edge Cases to Watch
  • Strutture di input vuote
  • Ingressi a elemento singolo
  • Grandi limiti numerici

Pronto a risolvere?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Apri nell'editor
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Risorse Python consigliate

Espandi le tue conoscenze con tutorial interattivi, foglietti illustrativi e confronti di codici correlati.