- ์ด๋ฐ ๋ฌธ์ ๊ฐ ๋์ค๋ฉด ์ปฌ๋ผ์ ๋ค๋ถํฐ ํ์ํ  ์์ ๊ฐ๋ ฅํ ์ด์ ์ด ์์
 
Solution
from typing import List
class Solution:
    def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
        # ๋ค๋ถํฐ ํ์ํ๋ ๊ฒ์ด ๋ ํจ์จ์ ์
        row, col = 0, len(matrix[0]) - 1
        while row < len(matrix) and col >= 0:
            current = matrix[row][col]
            if current == target:
                return True
            # ๋ค๋ถํฐ ํ์ํ๋๊น ๋ฐ๋ก ๋ค์ row๋ก ๋์ด๊ฐ ์ ์๋ ๊ฑฐ์
            if current < target:
                row += 1
                continue
            # ์ฐพ์ ๊ฐ๋ฅ์ฑ์ด ์์ผ๋ ์ผ์ชฝ์ผ๋ก ๊ฐ๋ฉด์ ํ์
            if current > target:
                col -= 1
        return False
 
Reference
        
      
      
      
      
  
     
    
      
    
  
Leave a comment