문자열

    [LeetCode] 12. Integer to Roman

    문제 Given an integer, convert it to a roman numeral. 1 0001, 23 -> 0023 num_s = str(num).zfill(4) return thousands[int(num_s[0])] + hundreds[int(num_s[1])] + tens[int(num_s[2])] + ones[int(num_s[3])] 후기 난이도 경우의 수가 많지 않다는 것을 파악하면 쉽게 구현할 수 있다. 로마 숫자의 범위가 거의 안 쓰는 F(5000)를 포함하더라도 원래 작지만, 만약 더 큰 수를 나타내는 표기가 많아져 주어지는 수의 범위가 커지더라도, 규칙성을 이용해 쉽게 풀 수 있을 것이다. 다른 풀이 경우의 수를 미리 정의하지 않고 if문을 통해 처리하면 시간과 메모리를 아낄..

    [LeetCode] 205. Isomorphic Strings (Daily Question)

    문제 Given two strings s and t, determine if they are isomorphic. Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself. 주어진 두 문자열 s, t가 같은 구조인지 판별하는 문제이다. 예를 들면, egg와 add는 구..