Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- html
- electron-packager
- camera access
- Each child in a list should have a unique "key" prop.
- ELECTRON
- silent printing
- 티스토리 성능
- device in use
- custom printing
- rolldown
- camera permission
- adb connect
- npm package
- 이미지 데이터 타입
- react-native
- github lfs
- Can't resolve
- Failed to compiled
- nextjs
- vercel git lfs
- dvh
- augmentedDevice
- Recoil
- ffi-napi
- github 100mb
- animation
- react-native-dotenv
- Git
- github pdf
- adb pair
Archives
- Today
- Total
Bleeding edge
[LeetCode] 1323. Maximum 69 Number - 자바스크립트 0614 본문
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
문제가 대소를 나타내는게 아닌 string에 대한 우선순위를 가지고 푸는 문제나, 무조건 한개는 바꿔야한다라고 하면 좋았을텐데... 지금 문제는 주어진숫자 6과 9를 서로 교환을 하는데 그중 한개를 바꿔서 가장 큰 숫자를 바꾸면된다. 즉, 첫번째로 만나는 6을 9로 바꾸고, 바꿀 것이 없다면 원래 주어진 num을 return하면 된다.
전체 풀이
var maximum69Number = function (num) {
let str = num.toString()
for (let i = 0; i < str.length; i++) {
if (str[i] === "6") {
str = str.slice(0, i) + "9" + str.slice(i + 1)
return str
}
}
return str
};