[leetcode-258]Add Digits(C)
来源:互联网 发布:自动加好友软件 编辑:程序博客网 时间:2024/05/19 18:43
问题描述:
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?
分析:这道题就是找规律。
代码如下:4ms
int addDigits(int num) { return (num-1)%9+1; }
0 0
- [leetcode-258]Add Digits(C)
- 【LeetCode-258】Add Digits(C++)
- [C]LeetCode:Add Digits
- LeetCode(258) Add Digits
- LeetCode 258. Add Digits 题解(C++)
- leetcode 258: Add Digits
- 258Add Digits - LeetCode
- leetCode #258 Add Digits
- [LeetCode 258] Add Digits
- LeetCode(258)Add Digits
- leetcode-258-Add Digits
- [leetcode 258]Add Digits
- [Leetcode]#258 Add Digits
- LeetCode 258----Add Digits
- LeetCode 258 : Add Digits
- 【LeetCode】258 Add Digits
- Leetcode - 258 - Add Digits
- leetcode 258 :Add Digits
- fgets和gets fread和fgets的区别
- c++程序的内存布局
- 如何使用Linux lsblk命令列出块设备信息
- pl sql连接oracle报错12154-解决X64操作系统PL/SQL连接报错问题 make sure you have the 32 bits oracle client installed
- POJ3273-----Monthly Expense
- [leetcode-258]Add Digits(C)
- POJ 1422 (最少路径覆盖)
- C#窗体控件简介
- 用vs2010开发基于VC++的MFC 串口通信一*****两台电脑同一个串口号之间的通信
- Android Support Library 22.1 简单介绍
- HDU 5384 Danganronpa
- ieee802组织
- 音频后处理基本概念
- 设计模式-职责链模式