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 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)