본문 바로가기

hello world/algorithm

오늘의 알고리즘: Plus One (66. LeetCode)

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

 

 

 

형변환해서 더한다음에 자릿수에 맞춰서 끼워넣었는데

문제에서 원하는건 단순 포문인듯.

 

[]int를 string으로 바꿔보기도 하고

 

func intToString(digits []int) string {

	b := ""
	for _, v := range digits {
		b += strconv.Itoa(v)
	}
	return b
}

 

big int 패키지도 사용

 

	x, _ := new(big.Int).SetString(stringInt, 10)
	y := big.NewInt(1)

	n := x.Add(x, y)                            //plus one
	intString := n.String()                     //to string

 

 

고랭에 big int 리미트는 없다고 한다. ㄷ ㄷ 

 

ispycode.com/Blog/golang/2016-10/What-is-the-max-value-of-bigint#:~:text=There%20is%20no%20explicit%20limit,as%20the%20system%20will%20allow.

 

What is the max value of bigint | golang blog

 

ispycode.com

 

 

strings 패키지좀 봐야겠다.

 

pkg.go.dev/strings?utm_source=gopls

 

strings · pkg.go.dev

Package strings implements simple functions to manipulate UTF-8 encoded strings. For information about UTF-8 strings in Go, see https://blog.golang.org/strings. func Compare(a, b string) int func Contains(s, substr string) bool func ContainsAny(s, chars st

pkg.go.dev