티스토리 뷰
https://leetcode.com/problems/reverse-integer/
Given a 32-bit signed integer, reverse digits of an integer.
32비트의 부호있는 정수가 있다, 정수의 숫자를 반전시켜라.
Example 1:
Input: 123
Output: 321
Example 2:
Input: -123
Output: -321
Example 3:
Input: 120
Output: 21
Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1].
For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
노트 :
32비트의 부호있는 정수 범위[−231, 231 − 1]의 환경이라고 가정하자.
이 문제의 목적을 위해 반전된 정수가 오버플로우 되면 0을 반환하는 것으로 가정한다.
푸는 방법은 2가지가 있는데 데이터를 문자로 취급해서 처리하는 방법과 수치로 취급해서 처리하는 방법이 있다.
문자로 처리하는 방법 :
수치를 계산하여 처리하는 방법 :
leetcode에서 위 방법들을 처리하면 문자는 28ms, 숫자는 15ms에 실행이 된다.
간단한 프로토타입이라면 문자열로 처리해도 되지만 자주 사용되는 코드라면 숫자를 계산하는 코드를 써야겠다.
'leetcode easy' 카테고리의 다른 글
9. Palindrome Number (0) | 2019.03.01 |
---|---|
1. Two Sum (0) | 2019.02.20 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 로그테스트 #콘솔로그테스트 #System.out
- Postgresql #MultiTruncate
- palindrome number
- PostgreSQL #FOR UPDATE #SKIP LOCKED
- SnakeYAML
- leetcode
- logback #logstash #LoggingEventCompositeJsonEncoder #로그JSON
- reverse integer
- yaml
- Maven LF #메이븐 개행문자
- spring-integration
- opencv로qr코드인식
- lombok #maven build #sym
- spring #redis #redis-cluster
- aws #aws region #aws credential #aws region provider #aws credential provier
- mybatis @insert값 @update값
- PostgreSQL #sequnceName
- excel to markdown
- json
- multipleIntegrationFlow
- AWS #X-Ray
- add two numbers
- QR코드읽기 #ReadQRCode
- springintegration #파일감시 #디렉토리감시 #파일완료검사
- Two Sum
- cannotResolveSymbol
- excel table
- 로그파일인덱스
- Python #Powertools
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함