Number of Digit One

原创 2015年07月09日 16:07:01
public class Solution {
    public int countDigitOne(int n) {
        int result = 0;
        for (long m = 1; m <= n; m *= 10) {
            long left = n / m;
            long right = n % m;
            result += (left + 8) / 10 * m;
            if (left % 10 == 1) {
                result += right + 1;
            }
        }
        return result;
    }
}

leetcode 233: Number of Digit One

leetcode 233: Number of Digit One java python c++
  • xudli
  • xudli
  • 2015-07-08 07:53:14
  • 14496

233 - Number of Digit One

Number of Digit One  Total Accepted: 307 Total Submissions: 1853 Given an integer n, count th...
  • wangyunyun00
  • wangyunyun00
  • 2015-08-07 18:03:22
  • 1715

LeetCode-233.Number of Digit One

https://leetcode.com/problems/number-of-digit-one/ Given an integer n, count the total number o...
  • zmq570235977
  • zmq570235977
  • 2016-07-12 15:54:14
  • 234

LeetCode-Number of Digit One-解题报告

原题链接 https://leetcode.com/problems/number-of-digit-one/ Given an integer n, count the total numbe...
  • dd523762588
  • dd523762588
  • 2015-07-09 14:04:11
  • 1211

剑指offer 面试题32:从1到n整数中1出现的次数(leecode233. Number of Digit One) 题解

剑指offer 面试题32:从1到n整数中1出现的次数(Leecode233. Number of Digit One) 提交网址: http://www.nowcoder.com/prac...
  • yanglr2010
  • yanglr2010
  • 2016-05-04 00:47:45
  • 1213

杭电ACM 1041 Computer Transformation java代码详解AC

Computer Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java...
  • wangyang1354
  • wangyang1354
  • 2015-11-04 13:31:43
  • 978

poj 2680 Computer Transformation (dp+高精度)

Computer Transformation Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:...
  • clover_hxy
  • clover_hxy
  • 2016-10-25 15:12:25
  • 144

E - 这题有点难(就是算1变成01,0变成10)

E - 这题有点难 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St...
  • shi201619616
  • shi201619616
  • 2017-07-10 18:34:01
  • 275

ubunt 系统上安装 deb 出错解决方法 version number does not start with digit 

今天在安装一个wif 破解的软件,在安装ded 文件时候出错出错查信息如下 dpkg:处理 jre6u1.deb (--install)时出错:  parsing file '/var/lib/dp...
  • ssihc0
  • ssihc0
  • 2011-05-03 00:32:00
  • 4863

[LeetCode] Plus One - 整数字符转换相加

题目概述:Plus One - 整数加一 Given a non-negative number represented as an array of digits, plus one to the ...
  • Eastmount
  • Eastmount
  • 2015-09-09 05:19:20
  • 2077
收藏助手
不良信息举报
您举报文章:Number of Digit One
举报原因:
原因补充:

(最多只允许输入30个字)