cft
Become a CreatorSign inGet Started

LeetCode 258. Add Digits in F#

Solve 2022/02/08 LeetCode daily problem


user

Shohei Yoshida

4 months ago | 1 min read
Follow

leetcode-258-add-digits-f-i8bnl

URL

https://leetcode.com/problems/add-digits/

Code

https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/problems/0258/main.fsx

let rec toDigits n acc =

if n = 0

then

acc

else

toDigits (n / 10) ((n % 10) :: acc)

let rec addDigits (n: int) : int =

let sum = (toDigits n [])|> List.sum

if sum < 10

then

sum

else

addDigits sum

Upvote


user
Created by

Shohei Yoshida

Follow

A programmer of DeNA

A Programmer


people
Post

Upvote

Downvote

Comment

Bookmark

Share


Related Articles