From be323467935a1d99bbf15bd7a6bf74a569aeec84 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Mon, 28 Oct 2024 11:11:59 -0700 Subject: [PATCH] [LEET-3274] add 3274 --- .../algorithms/4th_thousand/README.md | 1 + .../solutions/fourththousand/_3274.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/fourththousand/_3274.java diff --git a/paginated_contents/algorithms/4th_thousand/README.md b/paginated_contents/algorithms/4th_thousand/README.md index 8bac23ce34..23444149a3 100644 --- a/paginated_contents/algorithms/4th_thousand/README.md +++ b/paginated_contents/algorithms/4th_thousand/README.md @@ -8,6 +8,7 @@ | 3289 | [The Two Sneaky Numbers of Digitville](https://leetcode.com/problems/the-two-sneaky-numbers-of-digitville/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3289.java) | | Easy | | 3285 | [Find Indices of Stable Mountains](https://leetcode.com/problems/find-indices-of-stable-mountains/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3285.java) | | Easy | | 3280 | [Convert Date to Binary](https://leetcode.com/problems/convert-date-to-binary/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3280.java) | | Easy | +| 3274 | [Check if Two Chessboard Squares Have the Same Color](https://leetcode.com/problems/check-if-two-chessboard-squares-have-the-same-color/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3274.java) | | Easy | | 3270 | [Find the Key of the Numbers](https://leetcode.com/problems/find-the-key-of-the-numbers/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3270.java) | | Easy | | 3264 | [Final Array State After K Multiplication Operations I](https://leetcode.com/problems/final-array-state-after-k-multiplication-operations-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3264.java) | | Easy | | 3263 | [Convert Doubly Linked List to Array I](https://leetcode.com/problems/convert-doubly-linked-list-to-array-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3263.java) | | Easy | diff --git a/src/main/java/com/fishercoder/solutions/fourththousand/_3274.java b/src/main/java/com/fishercoder/solutions/fourththousand/_3274.java new file mode 100644 index 0000000000..9882484b81 --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/fourththousand/_3274.java @@ -0,0 +1,25 @@ +package com.fishercoder.solutions.fourththousand; + +import java.util.HashSet; +import java.util.Set; + +public class _3274 { + public static class Solution1 { + public boolean checkTwoChessboards(String coordinate1, String coordinate2) { + return isBlack(coordinate2) == isBlack(coordinate1); + } + + private boolean isBlack(String coordinate) { + Set blackColsWithOddRows = new HashSet<>(); + blackColsWithOddRows.add('a'); + blackColsWithOddRows.add('c'); + blackColsWithOddRows.add('e'); + blackColsWithOddRows.add('g'); + if (blackColsWithOddRows.contains(coordinate.charAt(0))) { + return Character.getNumericValue(coordinate.charAt(1)) % 2 == 1; + } else { + return Character.getNumericValue(coordinate.charAt(1)) % 2 == 0; + } + } + } +}