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 - 1
are 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 ...
随机推荐
- [vuejs] 终端npm run dev 不能自动打开浏览器运行项目解决办法
终端执行: npm run dev 出现: I Your application is running here: http://localhost:8080 但并没有打开浏览器运行项目 解决办法: ...
- Redis---ZipList(压缩列表)
1.概述 压缩列表是一块连续的内存空间,元素之间紧挨着存储,没有任何冗余空间. Redis 为了节约内存空间使用,zset 和 hash 容器对象在元素个数较少的时候,采用压缩列表 (ziplist) ...
- Liferay开发实战(2):Service Builder生成持久化层,及开发服务层
本文Liferay适用版本:v6.2.ce-ga6版 Liferay的插件体系是:模型-视图-控制器的portlet MVC框架.MVC是一个伟大的用于Web应用程序的设计模式,在实际应用中还应处理持 ...
- npm包发布记录
下雪了,在家闲着,不如写一个npm 包发布.简单的 npm 包的发布网上有很多教程,我就不记录了.这里记录下,一个复杂的 npm 包发布,复杂指的构建环境复杂. 整个工程使用 rollup 来构建,其 ...
- vue教程2-08 自定义键盘信息、监听数据变化vm.$watch
vue教程2-08 自定义键盘信息 @keydown.up @keydown.enter @keydown.a/b/c.... 自定义键盘信息: Vue.directive('on').keyCode ...
- Bash重定向
1. 基础知识 文件描述符(File Descriptor),是进程对其所打开文件的索引,形式上是个非负整数.类 Unix 系统中,常用的特殊文件描述符如下: 文件描述符 名称 常用缩写 默认值 0 ...
- Python之Pyautogui模块20180125《PYTHON快速上手让繁琐的工作自动化》18章
复习 PyAutoGUI 的函数本章介绍了许多不同函数,下面是快速的汇总参考:moveTo(x,y)将鼠标移动到指定的 x.y 坐标.moveRel (xOffset,yOffset)相对于当前位置移 ...
- JDK的windows和Linux版本之下载(图文详解)
不多说,直接上干货! 简单说下,Eclipse需要Jdk,MyEclipse有自带的Jdk,除非是版本要求 http://www.oracle.com/technetwork/java/javase/ ...
- print默认在末尾添加一个换行符,但其实也可以不用!
白月黑羽今天给大家分享另外一个冷知识:) python中 print函数打印信息时默认添加一个换行符,所以你看到一条print语句,则单独占一行,那是否可以不要换行符呢? 答案是肯定的,当然可以,可用 ...
- C#基础篇二变量与变量类型
说到数据类型,先把基本的数据类型拿出来 byte 0 到 255 无符号 8 位整数sbyte -128 到 127 有符号 8 位整数short -32,768 到 32,767 有符号 16 位整 ...