코딩 테스트/leetcode
Number of Good Pairs
ornni
2024. 7. 12. 10:00
728x90
반응형
첫번째 코드
원소들을 비교해서 같은 경우 answer += 1을 하는 방법으로 정답을 구한다.
class Solution:
def numIdenticalPairs(self, nums: List[int]) -> int:
answer = 0
for i in range(len(nums)):
for j in range(i+1, len(nums)):
if nums[i] == nums[j]:
answer += 1
return answer
통과
링크
https://github.com/ornni/leetcode/tree/main/1512-number-of-good-pairs
leetcode/1512-number-of-good-pairs at main · ornni/leetcode
Collection of LeetCode questions to ace the coding interview! - Created using [LeetHub v3](https://github.com/raphaelheinz/LeetHub-3.0) - ornni/leetcode
github.com
반응형