梦想游戏人

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.

Could you do it without any loop/recursion in O(1) runtime?

``````class Solution {
public:
if(num<10)return num;
num%=9;
if(num ==0 )return 9;
return num;
}
};``````

### 梦想游戏人

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. Example: Input: 38 Output: 2 Explanation: The process is like: 3 + 8 = 11, 1......

woshixin
2018/12/11
0
0
[LeetCode] Plus One 加一运算

Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. 将一......

2017/12/11
0
0

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers ......

jdflyfly
2014/06/24
0
0

SnailTyan
2018/08/17
0
0

1.英文题目 You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit......

2018/11/06
0
0

day11

architect刘源源
7分钟前
0
0

Linux就该这么学

0
0
git 使用

1，首先在github配置好信息和仓库，然后在本地进行操作 git init git config user.name 'zhangwuer' git config user.email '56789053@qq.com' 2，与远程分支建立连接 git checkout -b test......

2
0
git checkout 命令详解

shzwork

7
0
【Nginx】Nginx多级代理，获取客户端真实请求IP以及每级代理IP

Nginx多级代理，获取客户端真实请求IP以及每级代理IP 如图所示，每一级nginx里的location配置里需要加上对应的配置，最后一级nginx是直接到应用，测试时为了方便，直接用echo模块去测试，打印...

5
0