150 najlepszych wywiadówŚredni

Najdłuższy podciąg rosnący

Szczegółowy przewodnik i implementacja Python dla problemu „Najdłuższego podciągu rosnącego”.

Oświadczenie o problemie

Średni

Biorąc pod uwagę tablicę liczb całkowitych nums, zwróć długość najdłuższego ściśle rosnącego podciągu.

Napisz funkcję lengthOfLIS(nums: List[int]) -> int.

Ograniczenia
  • 1 <= len(nums) <= 2500
  • -10^4 <= nums[i] <= 10^4

Przykłady

Example 1
Input
nums = [10,9,2,5,3,7,101,18]
Output
4
Explanation

The longest increasing subsequence is [2,3,7,101], therefore the length is 4.

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

The longest increasing subsequence is [0,1,2,3], length is 4.

Example 3
Input
nums = [7,7,7,7,7,7,7]
Output
1
Explanation

The longest increasing subsequence is [7], length is 1.

Need a Hint?
Rozważ użycie struktur danych specyficznych dla 1D DP, takich jak zestawy lub sterty.
Edge Cases to Watch
  • Puste struktury wejściowe
  • Wejścia jednoelementowe
  • Duże granice liczbowe

Gotowy do rozwiązania?

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

Otwórz w Edytorze
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

Polecane zasoby Pythona

Poszerzaj swoją wiedzę dzięki powiązanym interaktywnym samouczkom, ściągawkom i porównaniom kodów.