[코테 풀이] Delete Columns to Make Sorted

시내·2024년 6월 29일

Q_944) Delete Columns to Make Sorted

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

class Solution {
    public int minDeletionSize(String[] strs) {
        int deleted = 0;
        for (int i = 0; i < strs[0].length(); i++) {
            char[] letters = new char[strs.length];
            int ind = 0;
            for (int j = 0; j < strs.length; j++) {
                letters[ind++] = strs[j].charAt(i);
            }
            if (!isLexi(letters)) deleted++;
        }
        return deleted;
    }
    
    public boolean isLexi(char[] letters) {
        for (int i = 0; i < letters.length - 1; i++) {
            if (letters[i + 1] - letters[i] < 0) return false;
        }
        return true;
    }
}
profile
contact 📨 ksw08215@gmail.com

0개의 댓글