Code Signal_练习题_chessBoardCellColor
Given two cells on the standard chess board, determine whether they have the same color or not.
Example
For
cell1 = "A1"andcell2 = "C3", the output should bechessBoardCellColor(cell1, cell2) = true.
For
cell1 = "A1"andcell2 = "H3", the output should bechessBoardCellColor(cell1, cell2) = false.
我的解答:
def chessBoardCellColor(cell1, cell2):
return abs(int(cell1[1])-int(cell2[1])) % 2 == 0 if abs(ord(cell1[0]) - ord(cell2[0])) % 2 == 0 else abs(int(cell1[1])-int(cell2[1])) % 2 == 1
def chessBoardCellColor(cell1, cell2):
return (ord(cell1[0]) + int(cell1[1]) + ord(cell2[0]) + int(cell2[1])) % 2 == 0
膜拜大佬
Code Signal_练习题_chessBoardCellColor的更多相关文章
- 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 ...
- Code Signal_练习题_absoluteValuesSumMinimization
Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...
随机推荐
- Python 生成器的使用(yield)
一. 生成器就是一个特殊的迭代器, 使用关键字yield就可以生成一个生成器 def func(): for i in range(10): yield i item = func() yield i ...
- 从工程化角度讨论如何快速构建可靠React组件
前言 React 的开发也已经有2年时间了,先从QQ的家校群,转成做互动直播,主要是花样直播这一块.切换过来的时候,业务非常繁忙,接手过来的业务比较凌乱,也没有任何组件复用可言. 为了提高开发效率,去 ...
- Yii2 Apache + Nginx 路由重写
一.什么是路由重写 原本的HTTP访问地址: www.test.com/index.php?r=post/view&id=100 表示这个请求将由PostController 的 action ...
- Swift5 语言参考(五) 语句
在Swift中,有三种语句:简单语句,编译器控制语句和控制流语句.简单语句是最常见的,由表达式或声明组成.编译器控制语句允许程序更改编译器行为的各个方面,并包括条件编译块和行控制语句. 控制流语句用于 ...
- [Leetcode]316.去除重复字母
题目 贪心方法 用一个两个数组vector<int>cnt,vector<bool>in_right_place: string res:目前符合条件的字符串,到代码结束的时候 ...
- 前端安全 -- XSS攻击
XSS漏洞是最广泛.作用最关键的web安全漏洞之一.在绝大多数网络攻击中都是把XSS作为漏洞链中的第一环,通过XSS,黑客可以得到的最直接利益就是拿到用户浏览器的cookie,从而变相盗取用户的账号密 ...
- 再续session和cookie (网络整理)
摘要:虽然session机制在web应用程序中被采用已经很长时间了,但是仍然有很多人不清楚session机制的本质,以至不能正确的应用这一技术.本文将详细讨论session的工作机制并且对在Java ...
- 剑指offer二十之包含min函数的栈
一.题目 定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数. 二.思路 用一个栈dataStack保存数据,用另外一个栈minStack保存依次入栈最小的数.每次元素存入minSt ...
- python使用(四)
1.file_os_option.py2.file_option.py3.configfile_option.py4.logger_option.py 1.file_os_option.py # co ...
- 微信应用号来了,微信小程序开发教程!
关注,QQ群,微信应用号社区 511389428,511389428 微信应用开放的服务和组件包含如下: 视图容器:视图(View).滚动视图.Swiper 基础内容:图标.文本.进度条 表单组件:按 ...