{"id":8297,"date":"2021-04-03T11:28:02","date_gmt":"2021-04-03T18:28:02","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=8297"},"modified":"2021-04-03T11:29:15","modified_gmt":"2021-04-03T18:29:15","slug":"leetcode-1812-determine-color-of-a-chessboard-square","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/string\/leetcode-1812-determine-color-of-a-chessboard-square\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 1812. Determine Color of a Chessboard Square"},"content":{"rendered":"\n<p>You are given&nbsp;<code>coordinates<\/code>, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.leetcode.com\/uploads\/2021\/02\/19\/screenshot-2021-02-20-at-22159-pm.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Return&nbsp;<code>true<\/code><em>&nbsp;if the square is white, and&nbsp;<\/em><code>false<\/code><em>&nbsp;if the square is black<\/em>.<\/p>\n\n\n\n<p>The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first, and the number second.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> coordinates = \"a1\"\n<strong>Output:<\/strong> false\n<strong>Explanation:<\/strong> From the chessboard above, the square with coordinates \"a1\" is black, so return false.\n<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> coordinates = \"h3\"\n<strong>Output:<\/strong> true\n<strong>Explanation:<\/strong> From the chessboard above, the square with coordinates \"h3\" is white, so return true.\n<\/pre>\n\n\n\n<p><strong>Example 3:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> coordinates = \"c7\"\n<strong>Output:<\/strong> false\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>coordinates.length == 2<\/code><\/li><li><code>'a' &lt;= coordinates[0] &lt;= 'h'<\/code><\/li><li><code>'1' &lt;= coordinates[1] &lt;= '8'<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: Mod2<\/strong><\/h2>\n\n\n\n<p>return (row_index + col_index) % 2 == 0<\/p>\n\n\n\n<p>Time complexity: O(1)<br>Space complexity: O(1)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"c++\">class Solution {\npublic:\n  bool squareIsWhite(string coordinates) {\n    return ((coordinates[0] - 'a') + (coordinates[1] - '0')) % 2 == 0;\n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>You are given&nbsp;coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference. Return&nbsp;true&nbsp;if the square&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[119,222,4],"class_list":["post-8297","post","type-post","status-publish","format-standard","hentry","category-string","tag-chess","tag-easy","tag-string","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/8297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=8297"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/8297\/revisions"}],"predecessor-version":[{"id":8299,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/8297\/revisions\/8299"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=8297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=8297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=8297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}