Skip to content

Commit

Permalink
New Problem Solution - "1812. Determine Color of a Chessboard Square"
Browse files Browse the repository at this point in the history
  • Loading branch information
haoel committed Apr 6, 2021
1 parent 616e340 commit 8ac73b4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ LeetCode
|1818|[Minimum Absolute Sum Difference](https://leetcode.com/problems/minimum-absolute-sum-difference/) | [C++](./algorithms/cpp/minimumAbsoluteSumDifference/MinimumAbsoluteSumDifference.cpp)|Medium|
|1817|[Finding the Users Active Minutes](https://leetcode.com/problems/finding-the-users-active-minutes/) | [C++](./algorithms/cpp/findingTheUsersActiveMinutes/FindingTheUsersActiveMinutes.cpp)|Medium|
|1816|[Truncate Sentence](https://leetcode.com/problems/truncate-sentence/) | [C++](./algorithms/cpp/truncateSentence/TruncateSentence.cpp)|Easy|
|1812|[Determine Color of a Chessboard Square](https://leetcode.com/problems/determine-color-of-a-chessboard-square/) | [C++](./algorithms/cpp/determineColorOfAChessboardSquare/DetermineColorOfAChessboardSquare.cpp)|Easy|
|1808|[Maximize Number of Nice Divisors](https://leetcode.com/problems/maximize-number-of-nice-divisors/) | [C++](./algorithms/cpp/maximizeNumberOfNiceDivisors/MaximizeNumberOfNiceDivisors.cpp)|Hard|
|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|
|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|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Source : https://leetcode.com/problems/determine-color-of-a-chessboard-square/
// Author : Hao Chen
// Date : 2021-04-06

/*****************************************************************************************************
*
* You are given coordinates, a string that represents the coordinates of a square of the chessboard.
* Below is a chessboard for your reference.
*
* Return true if the square is white, and false if the square is black.
*
* The coordinate will always represent a valid chessboard square. The coordinate will always have the
* letter first, and the number second.
*
* Example 1:
*
* Input: coordinates = "a1"
* Output: false
* Explanation: From the chessboard above, the square with coordinates "a1" is black, so return false.
*
* Example 2:
*
* Input: coordinates = "h3"
* Output: true
* Explanation: From the chessboard above, the square with coordinates "h3" is white, so return true.
*
* Example 3:
*
* Input: coordinates = "c7"
* Output: false
*
* Constraints:
*
* coordinates.length == 2
* 'a' <= coordinates[0] <= 'h'
* '1' <= coordinates[1] <= '8'
******************************************************************************************************/

class Solution {
public:
bool squareIsWhite(string coordinates) {
return (coordinates[0] - 'a'+1) % 2 != (coordinates[1] - '0') % 2;
}
};

0 comments on commit 8ac73b4

Please sign in to comment.