Skip to content

Commit 71c1ccd

Browse files
committedFeb 5, 2025
Add solution #258
1 parent f2584f1 commit 71c1ccd

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
237|[Delete Node in a Linked List](./0237-delete-node-in-a-linked-list.js)|Easy|
206206
238|[Product of Array Except Self](./0238-product-of-array-except-self.js)|Medium|
207207
242|[Valid Anagram](./0242-valid-anagram.js)|Easy|
208+
258|[Add Digits](./0258-add-digits.js)|Easy|
208209
260|[Single Number III](./0260-single-number-iii.js)|Medium|
209210
263|[Ugly Number](./0263-ugly-number.js)|Easy|
210211
264|[Ugly Number II](./0264-ugly-number-ii.js)|Medium|

‎solutions/0258-add-digits.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* 258. Add Digits
3+
* https://leetcode.com/problems/add-digits/
4+
* Difficulty: Easy
5+
*
6+
* Given an integer num, repeatedly add all its digits until
7+
* the result has only one digit, and return it.
8+
*/
9+
10+
/**
11+
* @param {number} num
12+
* @return {number}
13+
*/
14+
var addDigits = function(num) {
15+
return num < 10 ? num : num % 9 === 0 ? 9 : num % 9;
16+
};

0 commit comments

Comments
 (0)
Please sign in to comment.