码迷,mamicode.com
首页 > 其他好文 > 详细

Code Signal_练习题_Circle of Numbers

时间:2018-08-13 23:56:10      阅读:619      评论:0      收藏:0      [点我收藏+]

标签:alt   pre   习题   哈哈   bsp   The   dia   style   hat   

Consider integer numbers from 0 to n - 1 written down along the circle in such a way that the distance between any two neighboring numbers is equal (note that 0 and n - 1are neighboring, too).

Given n and firstNumber, find the number which is written in the radially opposite position to firstNumber.

Example

For n = 10 and firstNumber = 2, the output should be
circleOfNumbers(n, firstNumber) = 7.

技术分享图片

 

我的解答:

def circleOfNumbers(n, firstNumber):
    return (firstNumber+n/2) % n

 

技术分享图片
我的解法和排名第一的大佬写的一样....哈哈哈
膜拜大佬

 

Code Signal_练习题_Circle of Numbers

标签:alt   pre   习题   哈哈   bsp   The   dia   style   hat   

原文地址:https://www.cnblogs.com/YD2018/p/9471656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!