파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2023. 1. 3. 23:45

https://leetcode.com/problems/delete-columns-to-make-sorted/

 

Delete Columns to Make Sorted - LeetCode

Delete Columns to Make Sorted - You are given an array of n strings strs, all of the same length. The strings can be arranged such that there is one on each line, making a grid. For example, strs = ["abc", "bce", "cae"] can be arranged as: abc bce cae You

leetcode.com

처음에 문제를 잘 이해 못해서 살짝 헤맴.
가로로 검증을 해야되는게 아니라 세로로 검증을 하는거였음.

class Solution:
    def minDeletionSize(self, strs: List[str]) -> int:
        res = 0
        for i in range(len(strs[0])):
            s = []
            for j in range(len(strs)):
                s.append(strs[j][i])
            if s == sorted(s):
                continue
            res += 1            
        return res
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2023.01.05
Today's Challenge  (0) 2023.01.04
Today's Challenge  (0) 2023.01.02
Today's Challenge  (0) 2023.01.01
Today's Challenge  (0) 2022.12.31
Comments