diff --git a/src/main/java/leetcode/editor/cn/DetermineColorOfAChessboardSquare.java b/src/main/java/leetcode/editor/cn/DetermineColorOfAChessboardSquare.java new file mode 100644 index 0000000..bffc128 --- /dev/null +++ b/src/main/java/leetcode/editor/cn/DetermineColorOfAChessboardSquare.java @@ -0,0 +1,67 @@ +//给你一个坐标 coordinates ,它是一个字符串,表示国际象棋棋盘中一个格子的坐标。下图是国际象棋棋盘示意图。 +// +// +// +// 如果所给格子的颜色是白色,请你返回 true,如果是黑色,请返回 false 。 +// +// 给定坐标一定代表国际象棋棋盘上一个存在的格子。坐标第一个字符是字母,第二个字符是数字。 +// +// +// +// 示例 1: +// +// +//输入:coordinates = "a1" +//输出:false +//解释:如上图棋盘所示,"a1" 坐标的格子是黑色的,所以返回 false 。 +// +// +// 示例 2: +// +// +//输入:coordinates = "h3" +//输出:true +//解释:如上图棋盘所示,"h3" 坐标的格子是白色的,所以返回 true 。 +// +// +// 示例 3: +// +// +//输入:coordinates = "c7" +//输出:false +// +// +// +// +// 提示: +// +// +// coordinates.length == 2 +// 'a' <= coordinates[0] <= 'h' +// '1' <= coordinates[1] <= '8' +// +// Related Topics 字符串 +// 👍 4 👎 0 + +package leetcode.editor.cn; +//1812:判断国际象棋棋盘中一个格子的颜色 +public class DetermineColorOfAChessboardSquare{ + public static void main(String[] args) { + //测试代码 + Solution solution = new DetermineColorOfAChessboardSquare().new Solution(); + } + //力扣代码 + //leetcode submit region begin(Prohibit modification and deletion) +class Solution { + public boolean squareIsWhite(String coordinates) { + char[] chars = coordinates.toCharArray(); + if ((chars[0] - chars[1]) % 2 == 0) { + return false; + } else { + return true; + } + } +} +//leetcode submit region end(Prohibit modification and deletion) + +} \ No newline at end of file diff --git a/src/main/java/leetcode/editor/cn/DetermineColorOfAChessboardSquare.md b/src/main/java/leetcode/editor/cn/DetermineColorOfAChessboardSquare.md new file mode 100644 index 0000000..d101871 --- /dev/null +++ b/src/main/java/leetcode/editor/cn/DetermineColorOfAChessboardSquare.md @@ -0,0 +1,43 @@ +

给你一个坐标 coordinates ,它是一个字符串,表示国际象棋棋盘中一个格子的坐标。下图是国际象棋棋盘示意图。

+ +

+ +

如果所给格子的颜色是白色,请你返回 true,如果是黑色,请返回 false 。

+ +

给定坐标一定代表国际象棋棋盘上一个存在的格子。坐标第一个字符是字母,第二个字符是数字。

+ +

 

+ +

示例 1:

+ +
+输入:coordinates = "a1"
+输出:false
+解释:如上图棋盘所示,"a1" 坐标的格子是黑色的,所以返回 false 。
+
+ +

示例 2:

+ +
+输入:coordinates = "h3"
+输出:true
+解释:如上图棋盘所示,"h3" 坐标的格子是白色的,所以返回 true 。
+
+ +

示例 3:

+ +
+输入:coordinates = "c7"
+输出:false
+
+ +

 

+ +

提示:

+ + +
Related Topics
  • 字符串
  • \n
  • 👍 4
  • 👎 0
  • \ No newline at end of file