258. Add Digits--LeetCode Record
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
For example:
Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.
Follow up:
Could you do it without any loop/recursion in O(1) runtime?
class Solution {
func addDigits(num: Int) -> Int {
if num < 10 {
return num
}
return num % 9 == 0 ? 9 : num % 9
}
}
相關文章
- [LeetCode] 258. Add DigitsLeetCodeGit
- Leetcode 258. Add DigitsLeetCodeGit
- react-recordReact
- Daily record-SeptemberAI
- add exttrail 和add rmttail總結AI
- git add all和git add .區別Git
- 實戰 Java 16 值型別 Record - 2. Record 的基本用法Java型別
- jQuery add()jQuery
- pl/sql record 詳解SQL
- delete duplication record in sql serverdeleteSQLServer
- Java 16 新特性:record類Java
- Erlang中的Record詳解
- 淺析 record 使用場景
- Record It for Mac錄屏軟體Mac
- Java 21 新特性:Record PatternsJava
- 脫離rails 使用Active RecordAI
- Homework record-Simple sorting
- gorm忽略報錯: record not foundGoORM
- DataTransferItemList.add()
- git add errorGitError
- add field security
- Warning:dns_get_record():AtemporaryservererroroccurredDNSServerError
- Record for Individual Project ( Word frequency program )Project
- Using Statspack to Record Explain Plan DetailsAI
- record:記錄(帶名元組)
- 不好分類的好題Record
- JavaScript select add()JavaScript
- 4.5.1.1 srvctl add asmASM
- 4.5.1.2 srvctl add databaseDatabase
- Dockerfile:ADD VS COPYDocker
- 撤銷git addGit
- 如何處理 No DMARC Record Found 問題
- supremum pseudo-record鎖影響REM
- Ext.js4.2.1 Ext.data.RecordJS
- 轉:Oracle 解鎖Record is locked by another useOracle
- 動態record陣列的應用陣列
- table和record 型別用作引數型別
- JDK14 新增關鍵字——recordJDK