π 944. Delete Columns to Make Sorted
Delete Columns to Make Sorted - LeetCode
κ°λ¨λ³΄μ΄λ λ¬Έμ λ€.
λ¬Έμ ν΄μμ strs = ["abc", "bce", "cae"] μ΄λ κ² κ°μ΄ μ£Όμ΄μ‘μλ | a | b | c | | b | c | e | | c | a | e |
μΈλ‘λ‘ a b c λ μ λ ¬λμ΄ μκ³
μΈλ‘λ‘ b c a λ μ λ ¬λμ΄ μμ§ μλ€.
κ·Έλμ b c a μΈ λλ²μ§Έ μ΄μ μ§μμΌ νκ³ μ£Όμ΄μ§ λ¬Έμμμ μ΄ λͺκ°λ₯Ό μ§μμΌ νλ?κ° λ¬Έμ μ΄λ€.
κ·Έλμ μΌλ¨ λΈλ£¨νΈ ν¬μ€λ‘ νμλ€.
class Solution:
def minDeletionSize(self, strs: List[str]) -> int:
del_col = 0
# strs[0][0] strs[1][0] str[2][0]
length = 0
if len(strs) > 0:
length = len(strs[0])
sorted_col = [[] for _ in range(0, len(strs[0]))]
for col in range(0, length):
for i in range(0, len(strs)):
sorted_col[col].append(strs[i][col])
for chars in sorted_col:
if chars != sorted(chars):
del_col += 1
return del_col
μλκ°β¦ λ무 μμ’λ€. μ λ λΉ λ₯΄κ² κ°μ μ ν΄λ³΄μ
class Solution:
def minDeletionSize(self, strs: List[str]) -> int:
del_col = 0
# strs[0][0] strs[1][0] str[2][0]
col_length = 0
if len(strs) > 0:
col_length = len(strs[0])
for col in range(0, col_length):
for i in range(0, len(strs)):
if i - 1 >= 0 and (strs[i][col] < strs[i - 1][col]):
del_col += 1
break
return del_col
μ΄μ°¨νΌ νλ²μ λμμΌ νλ for λ¬Έ μμμ νλ°©μ λλ΄λ € νλ€.
λ§μ‘±μ€λ½κ΅°..π€

κ·Όλ° λ λ리λ€? λ©λͺ¨λ¦¬ μ¬μ©μμ νμ€ν μ€μλλ° λλ¦° κ² κΈ°λΆμ΄ λμλ€
Chat GPTμκ² λ¦¬ν©ν λ§μ μμΌ°λλ λ κΉλνκ² λ§λ€μ΄μ€¬λ€. (리ν©ν λ§μ λ μνλκ² κ°λ€.)
class Solution:
def minDeletionSize(self, strs: List[str]) -> int:
deletions = 0
for col in range(len(strs[0])):
for i in range(1, len(strs)):
if strs[i][col] < strs[i-1][col]:
deletions += 1
break
return deletions
λ§μ½μ strsκ° 0λ³΄λ€ μμμ§λ©΄ μ΄λ»κ² νλκ³ νλλ
class Solution:
def minDeletionSize(self, strs: List[str]) -> int:
if not strs:
return 0
deletions = 0
for col in range(len(strs[0])):
for i in range(1, len(strs)):
if strs[i][col] < strs[i-1][col]:
deletions += 1
break
return deletions
if not strs:
return 0
μ΄κ±Έ λ£μΌλ©΄ λμ§ μλκ³ νλλΌ νλ₯νλ€. λλ³΄λ€ λ κΉλνκ² λ¦¬ν©ν λ§ ν΄μ€¬λ€.
μλκ°μ μ λ¬Όμ΄λ΄€λλ
class Solution:
def minDeletionSize(self, strs: List[str]) -> int:
deletions = 0
for col in range(len(strs[0])):
prev_char = strs[0][col]
for i in range(1, len(strs)):
if strs[i][col] < prev_char:
deletions += 1
break
prev_char = strs[i][col]
return deletions
μ΄λ κ² λ§λ€μ΄μ€¬λ€.
μβ¦ μ΄κ±΄ κ²°κ΅ λ΄ μ½λλ μλμ°¨μ΄λ ν¬μ§ μμ κ² κ°λ€.
κ·Έλμ λ¬Έμ λ₯Ό νμ΄λ¬λΌ νλ€.
κ·Έλ¬λλ νμ΄μ€ λ΅μ μ΄κ²κ³Ό κ°λ€.
def minDeletionSize(strs):
deletions = 0
for col in range(len(strs[0])):
for i in range(1, len(strs)):
if strs[i][col] < strs[i-1][col]:
deletions += 1
break
return deletions
μμ 리ν©ν λ§ν λ΅κ³Ό κ°λ€.
ν β¦ κ²°κ΅ νμ΅λ λ°μ΄ν°μ μν΄μ λ΅μ μ£Όλκ±°λΌ νκ³κ° μλ?
λμ€μ 4.0 λ²μ μ΄ λμ€λ©΄ λ ν₯μλ λ΅μ μ£Όλ €λ? κΆκΈνκΈ΄νλ€.
(PS. λ€λ₯Έ μ¬λλ€μ΄ νΌ κ²λ€λ μμ λ΅κ³Ό μ μ¬νλ€λ κ²μ μ μ μμλ€.)