算法系列(9) LeetCode256
来源:互联网 发布:管家婆网络远程软件 编辑:程序博客网 时间:2024/05/23 14:45
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?
/** * @param {number} num * @return {number} */var addDigits = function(num) { while(num.toString().length>1){ var sum=0; while(num!=0){ sum += num%10; num = ~~(num/10); } num = sum; } return num;};
阅读全文
0 0
- 算法系列(9) LeetCode256
- [LeetCode256]Paint House
- 算法系列9《MD5》
- 【算法系列-9】二分查找
- (积累系列—算法)冒泡算法
- Hash算法系列-具体算法(HashedWheelTimer)
- 算法系列(1)排序算法
- USACO算法系列(小结)
- 推荐算法系列(一)
- 算法系列(一)基本概念
- 算法系列(2)leetcode283
- 算法系列(3)leetcode27
- 算法系列(4) leetcode26
- 算法系列(5) leetcode350
- 算法系列(6) leetcode1
- 算法系列(8)LeetCode389
- 算法细节系列(9):动态规划之01背包
- C#算法系列(9)——栈
- 给初中级JAVA准备的面试题
- org.springframework.web.context.ContextLoaderListener解决办法
- 单链表的19个功能程序实例
- Kafka主要参数详解
- PayPal支付问题2017-6-30
- 算法系列(9) LeetCode256
- JNI/NDK开发指南(十一)——JNI异常处理
- MATLAB2017a如何绘制折线图
- 【LeetCode】268. Missing Number
- spring boot实战(第十四篇)整合RabbitMQ源码分析前言
- gitlab新建项目过程和添加用户
- MyEclipse 如何安装FreeMarker 插件
- Android开发中一些你需要知道的图片相关知识和网站推荐分享
- 未接电话和未读短信监听