题解 | #求解立方根#

求解立方根

https://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    while(line = await readline()){
        const num = Number(line)
        const x = 0.0001;
        let low = Math.min(-1,num)
        let high = Math.max(1,num)
        let center = (low+high)/2
        while(Math.abs(center**3 - num) >= x){
            if(center**3<num){
                low = center
            }else{
                high = center
            }
            center = (low+high)/2
        }
        console.log(center.toFixed(1))
    }
}()

全部评论

相关推荐

点赞 评论 收藏
分享
爱吃肉的伊登在写日记:好棒,27届简历能做成这个样子,但是第一个项目感觉cover住难度还是不小的,特别是二面的时候肯定要对分布式系统设计这一块儿有高出正常面试者的水平才行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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