LeetCode 258. Add Digits in F#
Solve 2022/02/08 LeetCode daily problem
Shohei Yoshida
2 years ago | 1 min read
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
Created by
Shohei Yoshida
A Programmer
Post
Related Articles