HeYStRanGeR
article thumbnail

(23.05.09)

 

코테 문제 풀다보니까 문자열을 정렬해서 비교하면서 풀면 되겠다 싶은 문제들이 많다.

이때 간단하게 사용할 수 있는 것이 ''.join 과 sorted 이다.


 

1. 관련 프로그래머스 문제들과 내가 작성한 코드들

 

 

프로그래머스 lv0. A로 B만들기

<python />
def solution(before, after): before = ''.join(sorted(before.lower())) after = ''.join(sorted(after.lower())) if before == after: return 1 else: return 0

 

 

 

프로그래머스 lv.0 문자열 정렬하기(2)

<python />
def solution(my_string): my_string = my_string.lower() my_string = sorted(my_string) return ''.join(my_string)

 

 

 

프로그래머스 lv0. 외계어 사전

<python />
def solution(spell, dic): spell = ''.join(sorted(spell)) for i in range(len(dic)): dic[i] = ''.join(sorted(dic[i])) print(dic) if spell in dic: return 1 else: return 2

 

728x90
profile

HeYStRanGeR

@HeYStRanGeR

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!