반응형
https://leetcode.com/problems/reverse-integer/
Reverse Integer - 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
import kotlin.math.abs
import kotlin.math.pow
class Solution {
fun reverse(x: Int): Int {
var answer = 0
var xNum = x
var cnt = abs(x).toString().length - 1
while (xNum != 0) {
val accNum = (xNum % 10) * 10.0.pow(cnt)
if (answer + accNum > Integer.MAX_VALUE || answer + accNum < Integer.MIN_VALUE) {
return 0
}
answer += accNum.toInt()
xNum /= 10
cnt--
}
return answer
}
}
https://github.com/960813/leetcode-problems/commit/dcf999e969c6325aa69de8c3a33178f6435141a7
[7] Kotlin · 960813/leetcode-problems@dcf999e
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
github.com
반응형
☕️ Networking
기술 직군의 기술적인 교류, 커리어 이야기, 직군 무관 네트워킹 모두 환영합니다!
위클리 아카데미 오픈 채팅방(비밀번호: 9323)
kakaotalk: https://open.kakao.com/o/gyvuT5Yd