본문 바로가기

Algorithm/Implementation

(C++) - LeetCode (easy) 1323. Maximum 69 Number

반응형

https://leetcode.com/problems/maximum-69-number/description/

 

LeetCode - The World's Leading Online Programming Learning Platform

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

간단 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

num을 문자열로 바꿔서 numString에 저장해줍니다.

📔 풀이과정

가장 큰 수를 만드는 법은 6이 처음나온 부분을 9로 바꿔준 후 numString을 수로 바꿔 반환합니다.


📕 Code

📔 C++

class Solution {
public:
    int maximum69Number (int num) {
        string numString = to_string(num);
        for(auto &c : numString) {
            if (c == '6') {
                c = '9';
                break;
            }
        }
        return stoi(numString);
    }
};

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