Code Signal_练习题_Circle of Numbers
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 becircleOfNumbers(n, firstNumber) = 7.

我的解答:
def circleOfNumbers(n, firstNumber):
return (firstNumber+n/2) % n
我的解法和排名第一的大佬写的一样....哈哈哈
膜拜大佬
Code Signal_练习题_Circle of Numbers的更多相关文章
- Code Signal_练习题_isLucky
Ticket numbers usually consist of an even number of digits. A ticket number is considered lucky if t ...
- Code Signal_练习题_digitDegree
Let's define digit degree of some positive integer as the number of times we need to replace this nu ...
- Code Signal_练习题_Knapsack Light
You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...
- Code Signal_练习题_growingPlant
Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...
- Code Signal_练习题_arrayMaxConsecutiveSum
Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...
- Code Signal_练习题_differentSymbolsNaive
Given a string, find the number of different characters in it. Example For s = "cabca", th ...
- Code Signal_练习题_firstDigit
Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...
- Code Signal_练习题_extractEachKth
Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...
- Code Signal_练习题_stringsRearrangement
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...
随机推荐
- ReactNatvie遇到的错误
1:新版的React包中没有包含PropTypes,如果使用需要从‘prop-types’包中导入. 2: 'prop-types'包中直接定义‘PropTypes.style’是无效的,需要使用‘P ...
- Swift5 语言指南(二十六) 内存安全
默认情况下,Swift可以防止代码中发生不安全行为.例如,Swift确保变量在使用之前进行初始化,在取消分配后不访问内存,并检查数组索引是否存在越界错误. Swift还确保对同一内存区域的多次访问不会 ...
- 【dpdk】使用libpcap-PMD驱动收发包
ref: Dpdk programmer’s guide 1. 概述 dpdk不仅提供针对物理和虚拟网卡的pmd驱动(Poll Mode Drivers),还提供两个纯软件的pmd驱动,libpca ...
- Windows下Mongodb安装及配置
安装文件:MongoDB-win32-x86_64-2008plus-ssl-3.2.6-signed.msi 电脑配置:win7 64位 mongodb的安装很简单,设置好安装路径后,一直Next直 ...
- [原创]内网渗透JSP webSehll连接工具
工具: JspShellExec编译: VS2012 C# (.NET Framework v2.0)组织: K8搞基大队[K8team]作者: K8拉登哥哥博客: http://qqhack8.b ...
- android电量优化 总结
移动设备电池容量小,耗电较快(基本一天一充) ,故我们在应用开发使用相关组件和方法时候必须考虑耗电情况: 一 通过Battery Historian查看手机的耗电状况, 可以知道Android的在 ...
- Dev Label显示不同颜色字体
labelControl1.Text = "<size=14>Size = 14<br>" + "<b>Bold</b> ...
- Python中对矩阵的洗牌操作
[code] import numpy as np # 创建随机交换的索引 permutation = list(np.random.permutation(3)) # 创建矩阵X,Y X = np. ...
- Scala使用Akka模拟RPC机制代码
上代码: 另一个版本(自己加注释):http://www.cnblogs.com/DreamDrive/p/6740440.html RemoteMessage.scala trait Remote ...
- sql练习(针对Mysql)
创建表: DROP TABLE DEPT; --部门表 CREATE TABLE DEPT( DEPTNO int PRIMARY KEY, DNAME ) , --部门名称 LOC ) ---部门地 ...