소프트웨어에 대한 모든 것

LeetCode 풀기 - 709. To Lower Case 본문

알고리즘/LeetCode

LeetCode 풀기 - 709. To Lower Case

앤테바 2021. 11. 6. 10:41
반응형

709. To Lower Case

https://leetcode.com/problems/to-lower-case/

 

To Lower Case - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

문제)

솔루션1)

class Solution:
    def toLowerCase(self, s: str) -> str:            
        lower = list(s)
        for i, c in enumerate(lower):
            # 대문자인 경우, 소문자로 변경            
            if 'A' <= c <= 'Z':
                lower[i] = chr(ord('a') + (ord(c) - ord('A')))
            
        return ''.join(lower)

솔루션2)

 class Solution:
     def toLowerCase(self, s: str) -> str:
         return s.lower()

 

반응형
Comments