From d605bc30f63b30ba8f4e6f0c9ccfa2dfe07dff10 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Tue, 24 Mar 2026 08:05:32 +0800 Subject: [PATCH 1/2] Refactor LeetCode 2124: Check if All A's Appears Before All B's to new directory structure - Migrate solution from String/ directory to problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/ - Add docstring with time and space complexity analysis - Rename method from checkString to check_string (snake_case) - Update variable name from b_appear to is_b_appear --- .... Check if All A's Appears Before All B's.py | 10 ---------- .../__init__.py | 0 .../solution.py | 17 +++++++++++++++++ 3 files changed, 17 insertions(+), 10 deletions(-) delete mode 100644 String/2124. Check if All A's Appears Before All B's.py create mode 100644 problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/__init__.py create mode 100644 problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/solution.py diff --git a/String/2124. Check if All A's Appears Before All B's.py b/String/2124. Check if All A's Appears Before All B's.py deleted file mode 100644 index a38714c..0000000 --- a/String/2124. Check if All A's Appears Before All B's.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def checkString(self, s: str) -> bool: - b_appear = False - for c in s: - if c == 'b': - b_appear = True - else: - if b_appear: - return False - return True diff --git a/problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/__init__.py b/problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/solution.py b/problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/solution.py new file mode 100644 index 0000000..82c89be --- /dev/null +++ b/problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/solution.py @@ -0,0 +1,17 @@ +# Tags: String +class Solution: + def check_string(self, s: str) -> bool: + """ + Time Complexity: O(n) where n is the length of string s + - We iterate through the string exactly once + Space Complexity: O(1) + - Only a single boolean variable is used + """ + is_b_appear = False + for c in s: + if c == 'b': + is_b_appear = True + else: + if is_b_appear: + return False + return True From 569e546394aa6bc33c0265cafeb296c6af713ace Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Tue, 24 Mar 2026 08:05:43 +0800 Subject: [PATCH 2/2] Add test cases for LeetCode 2124: Check if All A's Appears Before All B's --- .../test_solution.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/test_solution.py diff --git a/problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/test_solution.py b/problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/test_solution.py new file mode 100644 index 0000000..2014207 --- /dev/null +++ b/problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/test_solution.py @@ -0,0 +1,15 @@ +import pytest +from tests.base_test import BaseTestSolution +from .solution import Solution + + +class TestSolution(BaseTestSolution): + solution = Solution() + + @pytest.mark.parametrize("method_name, s, expected, timeout", [ + ('check_string', "aaabbb", True, None), + ('check_string', "abab", False, None), + ('check_string', "bbb", True, None), + ]) + def test_check_string(self, method_name, s, expected, timeout): + self._run_test(self.solution, method_name, (s,), expected, timeout)