[Leet Code] Determine Color of a Chessboard Square

Input: coordinates = "a1"
Output: false
Explanation: From the chessboard above, the square with coordinates "a1" is black, so return false.
Input: coordinates = "h3"
Output: true
Explanation: From the chessboard above, the square with coordinates "h3" is white, so return true.
Input: coordinates = "c7"
Output: false
class Solution(object):
def squareIsWhite(self, coordinates):
"""
:type coordinates: str
:rtype: bool
"""
values = {"a":1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8}
if ((values[coordinates[0]] % 2 == 0 and int(coordinates[1]) % 2 == 0) or (int(values[coordinates[0]]) % 2 != 0 and int(coordinates[1]) % 2 != 0)):
return False
elif ((values[coordinates[0]] % 2 == 0 and int(coordinates[1]) % 2 != 0) or (values[coordinates[0]] % 2 != 0 and int(coordinates[1]) % 2 == 0)):
return True

--

--

--

Learning, and posting my findings!

Love podcasts or audiobooks? Learn on the go with our new app.

Metrics to evaluate software engineers

No Code ScheduleOnce and Salesforce Integration

A Brief Overview of Quantum Ledger Database

Day 19

Chasing perfection will only lead you to one end, and that’s burn out.

File Operations in Java

FinOps — Why, What and How

Start to Robotics Programmer(EN)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matthew Boyd

Matthew Boyd

Learning, and posting my findings!

More from Medium

Iterator Class For Inorder Traversal Of A Binary Tree

Algorithms Challenge Part 2

ARTS Week 23

Solving with Intuition#1Rotate Array