Skip to content

Commit 8ac73b4

Browse files
committed
New Problem Solution - "1812. Determine Color of a Chessboard Square"
1 parent 616e340 commit 8ac73b4

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ LeetCode
1313
|1818|[Minimum Absolute Sum Difference](https://leetcode.com/problems/minimum-absolute-sum-difference/) | [C++](./algorithms/cpp/minimumAbsoluteSumDifference/MinimumAbsoluteSumDifference.cpp)|Medium|
1414
|1817|[Finding the Users Active Minutes](https://leetcode.com/problems/finding-the-users-active-minutes/) | [C++](./algorithms/cpp/findingTheUsersActiveMinutes/FindingTheUsersActiveMinutes.cpp)|Medium|
1515
|1816|[Truncate Sentence](https://leetcode.com/problems/truncate-sentence/) | [C++](./algorithms/cpp/truncateSentence/TruncateSentence.cpp)|Easy|
16+
|1812|[Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square/) | [C++](./algorithms/cpp/determineColorOfAChessboardSquare/DetermineColorOfAChessboardSquare.cpp)|Easy|
1617
|1808|[Maximize Number of Nice Divisors](https://leetcode.com/problems/maximize-number-of-nice-divisors/) | [C++](./algorithms/cpp/maximizeNumberOfNiceDivisors/MaximizeNumberOfNiceDivisors.cpp)|Hard|
1718
|1807|[Evaluate the Bracket Pairs of a String](https://leetcode.com/problems/evaluate-the-bracket-pairs-of-a-string/) | [C++](./algorithms/cpp/evaluateTheBracketPairsOfAString/EvaluateTheBracketPairsOfAString.cpp)|Medium|
1819
|1806|[Minimum Number of Operations to Reinitialize a Permutation](https://leetcode.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation/) | [C++](./algorithms/cpp/minimumNumberOfOperationsToReinitializeAPermutation/MinimumNumberOfOperationsToReinitializeAPermutation.cpp)|Medium|
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Source : https://leetcode.com/problems/determine-color-of-a-chessboard-square/
2+
// Author : Hao Chen
3+
// Date : 2021-04-06
4+
5+
/*****************************************************************************************************
6+
*
7+
* You are given coordinates, a string that represents the coordinates of a square of the chessboard.
8+
* Below is a chessboard for your reference.
9+
*
10+
* Return true if the square is white, and false if the square is black.
11+
*
12+
* The coordinate will always represent a valid chessboard square. The coordinate will always have the
13+
* letter first, and the number second.
14+
*
15+
* Example 1:
16+
*
17+
* Input: coordinates = "a1"
18+
* Output: false
19+
* Explanation: From the chessboard above, the square with coordinates "a1" is black, so return false.
20+
*
21+
* Example 2:
22+
*
23+
* Input: coordinates = "h3"
24+
* Output: true
25+
* Explanation: From the chessboard above, the square with coordinates "h3" is white, so return true.
26+
*
27+
* Example 3:
28+
*
29+
* Input: coordinates = "c7"
30+
* Output: false
31+
*
32+
* Constraints:
33+
*
34+
* coordinates.length == 2
35+
* 'a' <= coordinates[0] <= 'h'
36+
* '1' <= coordinates[1] <= '8'
37+
******************************************************************************************************/
38+
39+
class Solution {
40+
public:
41+
bool squareIsWhite(string coordinates) {
42+
return (coordinates[0] - 'a'+1) % 2 != (coordinates[1] - '0') % 2;
43+
}
44+
};

0 commit comments

Comments
 (0)