leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 0615ec828290fa7131cb882fbd3d0fd1e536cfbb
parent 59716e13b8063037239c3dba8e7fa22ae5104c9e
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Wed, 26 Apr 2023 16:42:28 +0200

Daily Problem

Diffstat:
AProblems/0258.cpp | 11+++++++++++
MREADME.md | 1+
2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/Problems/0258.cpp b/Problems/0258.cpp @@ -0,0 +1,11 @@ +class Solution { +public: + int addDigits(int num) { + while (num >= 10) { + int sum = 0; + do { sum += num % 10; } while ((num /= 10) > 0); + num = sum; + } + return num; + } +}; diff --git a/README.md b/README.md @@ -207,6 +207,7 @@ for solving problems. | 0240 | Medium | [Search a 2D Matrix II](Problems/0240.cpp) | | 0242 | Easy | [Valid Anagram](Problems/0242.cpp) | | 0257 | Easy | [Binary Tree Paths](Problems/0257.cpp) | +| 0258 | Easy | [Add Digits](Problems/0258.cpp) | | 0263 | Easy | [Ugly Number](Problems/0263.cpp) | | 0264 | Medium | [Ugly Number II](Problems/0264.cpp) | | 0268 | Easy | [Missing Number](Problems/0268.cpp) |