[LeetCode] PlusOne (Go)

2021. 11. 14. 22:51· Algorithm/Go

 

https://leetcode.com/problems/plus-one/

 

Plus One - 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

 

func main() {
	digits := []int{8, 9, 9}
	for i := len(digits) - 1; i >= 0; i-- {
		if digits[i] != 9 {
			digits[i]++
			break
		}
		digits[i] = 0
		if i == 0 {
			digits = append([]int{1}, digits...)
		}
	}
	fmt.Println(digits)
}

/*
제출코드

func plusOne(digits []int) []int {
	for i := len(digits) - 1; i >= 0; i-- {
		if digits[i] != 9 {
			digits[i]++
			break
		}
		digits[i] = 0
		if i == 0 {
			digits = append([]int{1}, digits...)
		}
	}
	return digits
}
*/

'Algorithm > Go' 카테고리의 다른 글

[Leetcode] Two Sum (Go)  (0) 2021.12.06
[프로그래머스] 로또의 최고 순위와 최저 순위 (Go)  (0) 2021.11.28
[프로그래머스] 음양 더하기 (Go)  (0) 2021.11.22
[프로그래머스] 핸드폰 번호 가리기 (Go)  (0) 2021.11.08
[프로그래머스] 나머지가 1이 되는 수 찾기 (Go)  (0) 2021.10.24
'Algorithm/Go' 카테고리의 다른 글
  • [프로그래머스] 로또의 최고 순위와 최저 순위 (Go)
  • [프로그래머스] 음양 더하기 (Go)
  • [프로그래머스] 핸드폰 번호 가리기 (Go)
  • [프로그래머스] 나머지가 1이 되는 수 찾기 (Go)
임쟌
임쟌
임쟌
Jian's Blog
임쟌
전체
오늘
어제

공지사항

  • [자기소개]
  • 쟌's Blog (227)
    • Language (32)
      • Python (8)
      • Go (24)
      • Java (0)
    • Framework (10)
      • Django (9)
      • Gin (1)
      • Spring boot (0)
      • Fiber (0)
    • Database (10)
      • PostgreSQL (8)
      • MySQL (0)
      • Redis (2)
    • Server (51)
      • Linux (16)
      • Git (12)
      • Oracle Cloud Infrastructure (13)
      • Mac (4)
      • Docker (4)
      • RabbitMQ (0)
      • ETC (2)
    • Operating System (0)
      • OS (0)
    • Algorithm (22)
      • Go (22)
      • Python (0)
    • Exam Certification (4)
    • Daily Life (27)
      • Review (21)
      • Diary (6)
    • 이공계전문기술연수 (71)
      • Java (17)
      • Database (8)
      • HTML | CSS (13)
      • JavaScript | jQuery (6)
      • Servlet | JSP (16)
      • Spring Framework (11)

인기 글

최근 댓글

최근 글

hELLO · Designed By 정상우.v4.2.2
임쟌
[LeetCode] PlusOne (Go)
상단으로

티스토리툴바

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.