알고리즘/leetcode
[LeetCode][JavaScript] 1323. Maximum 69 Number
CooNiHong
2021. 7. 29. 14:39
[LeetCode][JavaScript] 1323. Maximum 69 Number
문제 출처: https://leetcode.com/problems/maximum-69-number/
Maximum 69 Number - 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
[직접 푼 코드]
var maximum69Number = function(num) {
var str = num.toString();
var res = str.replace('6','9');
return Number(res);
};
[문제 풀이]
1. number타입의 파라미터를 string타입으로 변환합니다. (toString 메서드)
2. 6을 9로 바꿔서 가장 큰 수를 찾아야 하기 때문에 제일 앞에 있는 6을 9로 바꿔줍니다. (replace 메서드)
알고리즘 스터디: https://github.com/ROUTINE-STUDY/Algorithm
GitHub - ROUTINE-STUDY/Algorithm: 초보 알고리즘 스터디 / 누구나 참여 가능
초보 알고리즘 스터디 / 누구나 참여 가능 :runner:. Contribute to ROUTINE-STUDY/Algorithm development by creating an account on GitHub.
github.com
누구나 참여 가능한 알고리즘 스터디입니다.
알고리즘뿐만 아니라 개발을 하면서 겪은 이슈, 이론을 정리하는 Routine-Study를 운영 중입니다.
728x90