zoukankan      html  css  js  c++  java
  • 1812. Determine Color of a Chessboard Square

    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.

    Constraints:

    • coordinates.length == 2
    • 'a' <= coordinates[0] <= 'h'
    • '1' <= coordinates[1] <= '8'

    注意找规律,从最简单的思路想起

    class Solution {
    publicbool squareIsWhite(string c) {
            return (c[0]+c[1])%2;
        }
    };
    class Solution:
        def squareIsWhite(self, c: str) -> bool:
            return (ord(c[0])+ord(c[1]))%2

    需要注意:C++中字符相加是可以的,会自动转成相应的ASCII相加,而Python中需要用ord函数,将字符转换成其对应的ASCII

  • 相关阅读:
    DC综合流程
    DC set_tcl脚本配置
    同步FIFO设计
    顺序脉冲 发生器
    状态机的写法
    verilog串并转换
    indexOf()
    jQuery 效果
    jQuery 事件
    jQuery css
  • 原文地址:https://www.cnblogs.com/Makerr/p/14656349.html
Copyright © 2011-2022 走看看