반응형
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;
}
};
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
(C++) - LeetCode (easy) 747. Largest Number At Least Twice of Others (0) | 2023.07.04 |
---|---|
(C++) - LeetCode (easy) 728. Self Dividing Numbers.cpp (0) | 2023.06.26 |
(C++) - LeetCode (easy) 693. Binary Number with Alternating Bits (0) | 2023.06.13 |
(C++) - LeetCode (easy) 682. Baseball Game (0) | 2023.06.12 |
(C++) - LeetCode (easy) 671. Second Minimum Node In a Binary Tree (0) | 2023.06.09 |