반응형
Theo | 테오
시행착오를 줄이는 방법 - 진태양
Theo | 테오
  • 분류 전체보기 (87)
    • General (32)
      • Essay (25)
      • Craftsmanship (3)
      • IT Meet & Hack (4)
    • Development (45)
      • News (4)
      • Architecture (4)
      • Spring Framework (7)
      • JVM (12)
      • React (0)
      • Next.js (0)
      • Web (1)
      • Git (2)
      • Algorithm (14)
      • Python (1)
    • Security (0)
      • PKI (0)
    • Infrastructure (1)
      • Kubernetes (0)
      • AWS (1)
    • Computer Science (1)
      • Network (1)
    • Civic Hacking (3)
      • Code for Korea (3)
    • Know-how (3)
      • IT Service (2)
      • Career (1)
    • Finance (1)
      • Portfolio (1)
      • Activity (0)
    • English (1)
      • Translation (1)

인기 글

블로그 메뉴

  • 홈
  • 관리
  • 방명록
hELLO · Designed By 정상우.
Theo | 테오

시행착오를 줄이는 방법 - 진태양

[LeetCode] 7. Reverse Integer (Kotlin)
Development/Algorithm

[LeetCode] 7. Reverse Integer (Kotlin)

2021. 12. 9. 18:46
반응형

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

    📑 간편 세금계산서 발행, 관리

    볼타: https://bolta.io

    볼타 채용: https://careers.bolta.io

    'Development/Algorithm' 카테고리의 다른 글
    • [LeetCode] 10. Regular Expression Matching (Kotlin)
    • [LeetCode] 8. String to Integer (atoi) (Kotlin)
    • [LeetCode] 6. Zigzag Conversion (Kotlin)
    • [LeetCode] 5. Longest Palindromic Substring (Kotlin)
    Theo | 테오
    Theo | 테오
    Java/Kotlin, Spring 백엔드 관련 기술을 익히고 공유합니다.

    티스토리툴바