DSA-SektionEinfach

Pythagoreische Drillinge

Detaillierte Anleitung und Python-Implementierung für das Problem „Pythagoräische Drillinge“.

Problemstellung

Einfach

Schreiben Sie eine Funktion contains_pythagorean_triplet(arr), die ein Array positiver Ganzzahlen arr annimmt und True zurückgibt, wenn das Array drei Ganzzahlen a, b und c enthält, sodass a^2 + b^2 = c^2 oder andernfalls False.

Einschränkungen
  • 3 <= len(arr) <= 1000
  • 1 <= arr[i] <= 1000

Beispiele

Example 1
Input
arr = [3, 1, 4, 6, 5]
Output
True
Explanation

3^2 + 4^2 = 9 + 16 = 25 = 5^2.

Example 2
Input
arr = [10, 4, 6, 12, 5]
Output
False
Need a Hint?
Erwägen Sie die Verwendung von Array-spezifischen Datenstrukturen wie Sets oder Heaps.
Edge Cases to Watch
  • Leere Eingabestrukturen
  • Einzelelementeingaben
  • Große numerische Grenzen

Bereit zur Lösung?

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

Im Editor öffnen
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

Empfohlene Python-Ressourcen

Erweitern Sie Ihr Wissen mit zugehörigen interaktiven Tutorials, Spickzetteln und Codevergleichen.