본문 바로가기

Algorithm/Implementation

(C++) - LeetCode (easy) 709. To Lower Case

반응형

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

 

To Lower Case - LeetCode

Can you solve this real interview question? To Lower Case - Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.   Example 1: Input: s = "Hello" Output: "hello" Example 2: Input: s = "here" Output: "he

leetcode.com

tolower함수를 사용해보는 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

정답 변수 ans를 선언해줍니다.

📔 풀이과정

s의 문자를 순회하며 tolower함수의 반환값을 ans뒤에 붙여줍니다.

📔 정답 출력 | 반환

ans를 반환합니다.


📕 Code

📔 C++

class Solution {
public:
    string toLowerCase(string s) {
        string ans;
        for(auto c : s) ans += tolower(c);
        return ans;
    }
};

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.