题解 | #数字序列中某一位的数字#

数字序列中某一位的数字

https://www.nowcoder.com/practice/29311ff7404d44e0b07077f4201418f5

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param n int整型 
     * @return int整型
     */
    public int findNthDigit (int n) {
        // write code here
        int i = 1;
        while(i * (Math.pow(10, i)) < n){
            n += Math.pow(10, i);
            i ++;
        }
        Integer num = n/i;
        String str = num.toString();
        return str.charAt(n % i) - '0';
    }
}

全部评论

相关推荐

06-25 09:33
厦门大学 Java
程序员饺子:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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