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的更多相关文章

  1. Code Signal_练习题_isLucky

    Ticket numbers usually consist of an even number of digits. A ticket number is considered lucky if t ...

  2. Code Signal_练习题_digitDegree

    Let's define digit degree of some positive integer as the number of times we need to replace this nu ...

  3. Code Signal_练习题_Knapsack Light

    You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...

  4. Code Signal_练习题_growingPlant

    Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...

  5. Code Signal_练习题_arrayMaxConsecutiveSum

    Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...

  6. Code Signal_练习题_differentSymbolsNaive

    Given a string, find the number of different characters in it. Example For s = "cabca", th ...

  7. Code Signal_练习题_firstDigit

    Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...

  8. Code Signal_练习题_extractEachKth

    Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...

  9. Code Signal_练习题_stringsRearrangement

    Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...

随机推荐

  1. Spring Boot切换为APR模式

    Spring Boot内置了tomcat容器,直接运行Application就可以启动web服务器. 在tomcat中提供了三种方式:BIO.NIO.APR. BIO tomcat7以下的版本都是BI ...

  2. centoos 安装hadoop集群

    环境准备 两台centoos系统服务器 H30(192.168.3.238) H31(192.168.3.237) H30为master,H31为slave,slave后续还可以再加机器: 先通过xs ...

  3. (干货) Android实现ImageVIew多点触控及双击缩放

    支持多点触控,放大自由移动,双击可以放大缩小.直接上代码: package com.cbt.view; import android.content.Context; import android.g ...

  4. 移动端font-size适配方案(续)

    概述 之前写过一篇移动端font-size适配方案,但是在实践过程中,还是发现当时的思维太局限了,视野太窄了,所以现在补充更新一下,记录下来,供以后开发时参考,相信对其他人也有用. 我上一篇博文主要有 ...

  5. mongoose 基础api 图表整理

    一.背景 今天看 mongoose 的基础 API,参考了下面的链接做了图表以供查阅. 参考资料: http://www.cnblogs.com/xiaohuochai/p/7215067.html ...

  6. flask框架--cookie,session

    今天我又给大家分享一下怎么用flask框架来实现像淘宝购物车一样存储数据,并且把存储的数据删除,这个方法可以用两个方法都可以做成,一个是cookie,另一个是session. session是依赖于c ...

  7. Python中对矩阵的洗牌操作

    [code] import numpy as np # 创建随机交换的索引 permutation = list(np.random.permutation(3)) # 创建矩阵X,Y X = np. ...

  8. Bash数组

    1. 数组申明 declare -a array 2. 数组赋值 #法1 array=(var1 var2 var3 ... varN) #法2 array=([]=var1 []=var2 []=v ...

  9. Android中实现activity的页面跳转并传值

    一个Android应用程序很少会只有一个Activity对象,如何在多个Activity之间进行跳转,而且能够互相传值是一个很基本的要求. 本次我们就讲一下,Android中页面跳转以及传值的几种方式 ...

  10. async & await 异步编程小示例,一看就懂

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...