Appearance
question:def reverseParentheses(s: str) -> str: Reverse the strings in each pair of matching parentheses, starting from the innermost one. The result should not contain any parentheses. >>> reverseParentheses("(abcd)") == "dcba" >>> reverseParentheses("(u(love)i)") == "iloveu" >>> reverseParentheses("(ed(et(oc))el)") == "leetcode" >>> reverseParentheses("abcdef") == "abcdef" >>> reverseParentheses("") == "" >>> reverseParentheses("a(bcdefghijkl(mno)p)q") == "apmnolkjihgfedcbq"
answer:def reverseParentheses(s: str) -> str: stack = [] for char in s: if char == ')': temp = [] while stack and stack[-1] != '(': temp.append(stack.pop()) stack.pop() # Removing the '(' stack.extend(temp) else: stack.append(char) return ''.join(stack)
question:def sum_even_numbers(numbers: List[int]) -> int: Returns the sum of the even integers in the provided list of numbers. Args: numbers (list of int): The list of integers to be processed. Returns: int: The sum of the even integers. >>> sum_even_numbers([1, 2, 3, 4, 5, 6]) 12 >>> sum_even_numbers([0, -2, 5, 8, 10]) 16 >>> sum_even_numbers([7, 1, 9]) 0 >>> sum_even_numbers([2, 4, 6, 8]) 20 >>> sum_even_numbers([-2, -4, -3, 3]) -6 >>> sum_even_numbers([]) 0
answer:def sum_even_numbers(numbers): Returns the sum of the even integers in the provided list of numbers. Args: numbers (list of int): The list of integers to be processed. Returns: int: The sum of the even integers. return sum(num for num in numbers if num % 2 == 0)
question:def is_leap_year(year: int) -> bool: Determines if the given year is a leap year. Parameters: year (int): The year to be checked Returns: bool: True if the year is a leap year, false otherwise >>> is_leap_year(2020) True >>> is_leap_year(1900) False >>> is_leap_year(2000) True >>> is_leap_year(2019) False >>> is_leap_year(-4) True pass
answer:def is_leap_year(year): Determines if the given year is a leap year. Parameters: year (int): The year to be checked Returns: bool: True if the year is a leap year, false otherwise if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): return True return False
question:def isPossibleToBalance(arr: List[int]) -> bool: Checks if it is possible to split the list into two non-empty parts with equal sums. >>> isPossibleToBalance([1, 1, 1, 2, 1]) # True >>> isPossibleToBalance([2, 1, 1, 2, 1]) # False >>> isPossibleToBalance([10, 10]) # True >>> isPossibleToBalance([1, -1, 2, -2, 2]) # True >>> isPossibleToBalance([10000, 10000, -20000, 10000, 10000]) # True >>> isPossibleToBalance([1, 1, 1, 1, 1]) # False >>> isPossibleToBalance([1, 1]) # True >>> isPossibleToBalance([1, 2]) # False # Your implementation goes here.
answer:def isPossibleToBalance(arr): Checks if it is possible to split the list into two non-empty parts with equal sums. total_sum = sum(arr) # If the total sum is odd, we can't split it into two equal parts if total_sum % 2 != 0: return False # We need to find a prefix sum that equals to half of the total sum half_sum = total_sum // 2 current_sum = 0 for i in range(len(arr) - 1): current_sum += arr[i] if current_sum == half_sum: return True return False