본문 바로가기
python-algorithm

leetcode 2965. Find Missing and Repeated Values

by 무적김두칠 2023. 12. 27.

https://leetcode.com/problems/find-missing-and-repeated-values/description/

 

Find Missing and Repeated Values - LeetCode

Can you solve this real interview question? Find Missing and Repeated Values - You are given a 0-indexed 2D integer matrix grid of size n * n with values in the range [1, n2]. Each integer appears exactly once except a which appears twice and b which is mi

leetcode.com

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution:
    def findMissingAndRepeatedValues(self, grid: List[List[int]]) -> List[int]:
        check = [0* (len(grid)**2 + 1)
        for i in grid:
            for j in i:
                check[j] += 1
        answer = [00]
 
        for i, v in enumerate(check):
            if v == 0:
                answer[1= i
            if v > 1:
                answer[0= i
        
        return answer
 
        
cs
반응형

'python-algorithm' 카테고리의 다른 글

leetcode 2951. Find the Peaks  (0) 2023.12.27
leetcode 2956. Find Common Elements Between Two Arrays  (0) 2023.12.27
백준 4388 받아올림  (0) 2023.12.27
백준 6550 부분 문자열  (2) 2023.12.23
백준 11723 집합  (1) 2023.12.23

댓글