题解 | #在二叉树中找到两个节点的最近公共祖先#

整数中1出现的次数(从1到n整数中1出现的次数)

http://www.nowcoder.com/practice/bd7f978302044eee894445e244c7eee6

public class Solution{ public int NumberOf1Between1AndN_Solution(int n){ int count = 0,bitNum = 1,high = n /10,cur = n % 10,low = 0; while(cur != 0 || high != 0){ if(cur < 1){ count += high * bitNum; }else if(cur == 1){ count += high*bitNum +low +1; }else{ count += (high+1)*bitNum; } low += cur * bitNum; cur = high % 10; high = high /10; bitNum *= 10; } return count; } }

我居南半坡 文章被收录于专栏

多刷题,积蓄力量,欢迎讨论

全部评论

相关推荐

做黑夜里的那道光:两年电赛完赛没必要写,纯扣分
双非本科求职如何逆袭
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务