https://leetcode.com/problems/array-nesting/
Array Nesting - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
class Solution:
def arrayNesting(self, nums: List[int]) -> int:
result = 0
for index in range(0, len(nums)):
length = 0
while nums[index] != -1:
length += 1
temp = nums[index]
nums[index] = -1
index = temp
else:
result = max(result, length)
return result
'알고리즘 > Leetcode' 카테고리의 다른 글
[leetcode/python3] 49. Group Anagrams (0) | 2022.04.26 |
---|---|
[leetcode/python3] 485. Max Consecutive Ones (0) | 2021.09.22 |
[leetcode/python3] 1. Two Sum (0) | 2021.08.03 |
[leetcode/python3] 1768.Merge Strings Alternately (0) | 2021.04.10 |
[leetcode/kotlin] 575.Distribute Candies (0) | 2021.03.16 |