From 9782608bbbe0988ca2e901f659e39f0ee0747ac2 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 3 Nov 2024 10:05:43 -0800 Subject: [PATCH] [LEET-3340] add 3340 --- .../algorithms/4th_thousand/README.md | 1 + .../solutions/fourththousand/_3340.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/fourththousand/_3340.java diff --git a/paginated_contents/algorithms/4th_thousand/README.md b/paginated_contents/algorithms/4th_thousand/README.md index 246f071f16..57002059ab 100644 --- a/paginated_contents/algorithms/4th_thousand/README.md +++ b/paginated_contents/algorithms/4th_thousand/README.md @@ -1,5 +1,6 @@ | # | Title | Solutions | Video | Difficulty | Tag |------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|---------------------------------------------------------------------- +| 3340 | [Check Balanced String](https://leetcode.com/problems/check-balanced-string/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3340.java) | | Easy | | 3330 | [Find the Original Typed String I](https://leetcode.com/problems/find-the-original-typed-string-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3330.java) | | Easy | | 3324 | [Find the Sequence of Strings Appeared on the Screen](https://leetcode.com/problems/find-the-sequence-of-strings-appeared-on-the-screen/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3324.java) | | Easy | | 3318 | [Find X-Sum of All K-Long Subarrays I](https://leetcode.com/problems/find-x-sum-of-all-k-long-subarrays-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3318.java) | | Easy | diff --git a/src/main/java/com/fishercoder/solutions/fourththousand/_3340.java b/src/main/java/com/fishercoder/solutions/fourththousand/_3340.java new file mode 100644 index 0000000000..276ff833e7 --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/fourththousand/_3340.java @@ -0,0 +1,18 @@ +package com.fishercoder.solutions.fourththousand; + +public class _3340 { + public static class Solution1 { + public boolean isBalanced(String num) { + int oddSum = 0; + int evenSum = 0; + for (int i = 0; i < num.length(); i++) { + if (i % 2 == 0) { + evenSum += Character.getNumericValue(num.charAt(i)); + } else { + oddSum += Character.getNumericValue(num.charAt(i)); + } + } + return oddSum == evenSum; + } + } +}