From 86d16fd7f109ce6541fdc90088dedbaaef6fc2f7 Mon Sep 17 00:00:00 2001 From: KDH Date: Tue, 17 Sep 2024 10:53:39 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A6=B0=ED=84=B0=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 6 +++--- backtracking/escape_maze/escape_maze.py | 4 +--- backtracking/n_queens/n_queens.py | 4 +--- backtracking/n_queens/test.py | 4 +--- coding_test/leetcode/decode_string/test.py | 3 +-- coding_test/leetcode/insertion_sort_list/test.py | 4 +--- .../median_of_two_sorted_arrays/solution.py | 12 ++---------- coding_test/leetcode/three_sum/test.py | 4 +--- coding_test/leetcode/ugly_number_3/solution.py | 10 +--------- coding_test/programmers/analog_watch.py | 10 ++-------- .../brute_force/number_baseball/test.py | 4 +--- .../brute_force/split_electric_grid.py | 5 +---- .../programmers/dfs_bfs/fill_puzzle_failed.py | 4 +--- coding_test/programmers/dfs_bfs/network/test.py | 16 ++++------------ coding_test/programmers/dfs_bfs/pickup_item.py | 15 +++------------ coding_test/programmers/graph/ranking.py | 4 +--- coding_test/programmers/hash/album.py | 4 +--- coding_test/programmers/select_dice.py | 9 ++------- .../programmers/sort/kth_number/solution.py | 5 +---- .../programmers/stack_queue/truck/test.py | 4 +--- compression/huffman/huffman.py | 4 +--- .../graph/adjacency_list/adjacency_list.py | 4 +--- .../graph/adjacency_matrix/adjacency_matrix.py | 4 +--- data_structures/hash_table/test.py | 4 +--- data_structures/heap/max_heap.py | 5 +---- data_structures/heap/min_heap.py | 5 +---- .../queue/circular_queue/circular_queue.py | 4 +--- .../queue/priority_queue/priority_queue.py | 5 +---- .../stack/calculator/infix_to_postfix.py | 5 +---- .../tree/red_black_tree/red_black_tree.py | 10 ++-------- .../longest_common_subsequence/simple_lcs.py | 4 +--- .../longest_common_subsequence/test.py | 8 ++------ search/text_search/knuth_morris_pratt.py | 4 +--- search/text_search/native_search.py | 4 +--- search/text_search/rabin_karp.py | 6 +++--- search/text_search/test.py | 4 +--- sort/bubble_sort/test.py | 4 +--- sort/quick_sort/test.py | 4 +--- 38 files changed, 52 insertions(+), 167 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 745a56b..0b7dbe9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,10 +4,10 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up python - uses: actions/setup-python@v2 - - uses: pre-commit/action@v2.0.0 + uses: actions/setup-python@v5 + - uses: pre-commit/action@v3.0.1 - name: Install pytest run: pip install pytest - name: Test diff --git a/backtracking/escape_maze/escape_maze.py b/backtracking/escape_maze/escape_maze.py index c0abfcc..b45e404 100644 --- a/backtracking/escape_maze/escape_maze.py +++ b/backtracking/escape_maze/escape_maze.py @@ -30,9 +30,7 @@ def parse_maze(maze: str) -> Tuple[MAZE, POSITION]: return maze_info, start_pos -def next_step( - maze: MAZE, current_pos: POSITION, direction: int -) -> Union[POSITION, bool]: +def next_step(maze: MAZE, current_pos: POSITION, direction: int) -> Union[POSITION, bool]: x, y = current_pos if direction == 0: diff --git a/backtracking/n_queens/n_queens.py b/backtracking/n_queens/n_queens.py index 12a2677..575f0ea 100644 --- a/backtracking/n_queens/n_queens.py +++ b/backtracking/n_queens/n_queens.py @@ -8,9 +8,7 @@ def is_safe(board: BOARD_TYPE, row: int) -> bool: current_row = 0 while current_row < row: - if board[current_row] == board[row] or ( - abs(board[current_row] - board[row]) == abs(current_row - row) - ): + if board[current_row] == board[row] or (abs(board[current_row] - board[row]) == abs(current_row - row)): return False current_row += 1 return True diff --git a/backtracking/n_queens/test.py b/backtracking/n_queens/test.py index 82417dc..f6cc614 100644 --- a/backtracking/n_queens/test.py +++ b/backtracking/n_queens/test.py @@ -10,9 +10,7 @@ def test_2_3_queens(self) -> None: def test_4_queens(self) -> None: result = n_queens(4) - self.assertEqual( - result, [[(1, 0), (3, 1), (0, 2), (2, 3)], [(2, 0), (0, 1), (3, 2), (1, 3)]] - ) + self.assertEqual(result, [[(1, 0), (3, 1), (0, 2), (2, 3)], [(2, 0), (0, 1), (3, 2), (1, 3)]]) self.assertEqual(len(result), 2) def test_8_queens(self) -> None: diff --git a/coding_test/leetcode/decode_string/test.py b/coding_test/leetcode/decode_string/test.py index d2ea832..28dc50b 100644 --- a/coding_test/leetcode/decode_string/test.py +++ b/coding_test/leetcode/decode_string/test.py @@ -9,6 +9,5 @@ def test_solution(): assert decode_string("abc3[cd]xyz") == "abccdcdcdxyz" assert decode_string("100[leetcode]") == "leetcode" * 100 assert ( - decode_string("3[z]2[2[y]pq4[2[jk]e1[f]]]ef") - == "zzzyypqjkjkefjkjkefjkjkefjkjkefyypqjkjkefjkjkefjkjkefjkjkefef" + decode_string("3[z]2[2[y]pq4[2[jk]e1[f]]]ef") == "zzzyypqjkjkefjkjkefjkjkefjkjkefyypqjkjkefjkjkefjkjkefjkjkefef" ) diff --git a/coding_test/leetcode/insertion_sort_list/test.py b/coding_test/leetcode/insertion_sort_list/test.py index f554732..3a039e3 100644 --- a/coding_test/leetcode/insertion_sort_list/test.py +++ b/coding_test/leetcode/insertion_sort_list/test.py @@ -3,7 +3,5 @@ def test_solution(): insertion_sort_list = Solution().insertionSortList - sorted_node = insertion_sort_list( - ListNode(4, ListNode(2, ListNode(1, ListNode(3)))) - ) + sorted_node = insertion_sort_list(ListNode(4, ListNode(2, ListNode(1, ListNode(3))))) assert list(node.val for node in sorted_node) == [1, 2, 3, 4] diff --git a/coding_test/leetcode/median_of_two_sorted_arrays/solution.py b/coding_test/leetcode/median_of_two_sorted_arrays/solution.py index 36cbfe8..14bd27f 100644 --- a/coding_test/leetcode/median_of_two_sorted_arrays/solution.py +++ b/coding_test/leetcode/median_of_two_sorted_arrays/solution.py @@ -19,18 +19,10 @@ def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: elif 0 < i and nums2[j] < nums1[i - 1]: imax = i - 1 else: - max_left = ( - max(nums1[i - 1], nums2[j - 1]) - if i and j - else nums1[i - 1] if i else nums2[j - 1] - ) + max_left = max(nums1[i - 1], nums2[j - 1]) if i and j else nums1[i - 1] if i else nums2[j - 1] if (m + n) % 2 == 1: return max_left - min_right = ( - min(nums1[i], nums2[j]) - if i != m and j != n - else nums2[j] if i == m else nums1[i] - ) + min_right = min(nums1[i], nums2[j]) if i != m and j != n else nums2[j] if i == m else nums1[i] return (max_left + min_right) / 2 diff --git a/coding_test/leetcode/three_sum/test.py b/coding_test/leetcode/three_sum/test.py index ef7b1fb..2447fa9 100644 --- a/coding_test/leetcode/three_sum/test.py +++ b/coding_test/leetcode/three_sum/test.py @@ -8,6 +8,4 @@ def setUp(self) -> None: self.solution = Solution().threeSum def test_case_1(self) -> None: - self.assertEqual( - self.solution([-1, 0, 1, 2, -1, -4]), [[-1, 0, 1], [-1, -1, 2]] - ) + self.assertEqual(self.solution([-1, 0, 1, 2, -1, -4]), [[-1, 0, 1], [-1, -1, 2]]) diff --git a/coding_test/leetcode/ugly_number_3/solution.py b/coding_test/leetcode/ugly_number_3/solution.py index bd0c61b..ae16737 100644 --- a/coding_test/leetcode/ugly_number_3/solution.py +++ b/coding_test/leetcode/ugly_number_3/solution.py @@ -4,15 +4,7 @@ class Solution: def nthUglyNumber(self, n: int, a: int, b: int, c: int) -> int: def fulfilled(num) -> bool: - total = ( - num // a - + num // b - + num // c - - num // ab - - num // ac - - num // bc - + num // abc - ) + total = num // a + num // b + num // c - num // ab - num // ac - num // bc + num // abc return total >= n def lcm(x, y) -> int: diff --git a/coding_test/programmers/analog_watch.py b/coding_test/programmers/analog_watch.py index 70254f4..6bed6e3 100644 --- a/coding_test/programmers/analog_watch.py +++ b/coding_test/programmers/analog_watch.py @@ -11,19 +11,13 @@ def solution(h1, m1, s1, h2, m2, s2): while t1 < datetime.datetime(2024, 8, 31, h2, m2, s2): s1_angle = t1.second * 360 / 60 m1_angle = (t1.minute * 360 / 60) + (t1.second * 360 / 60 / 60) - h1_angle = ( - (t1.hour % 12 * 360 / 12) - + (t1.minute * 360 / 60 / 12) - + (t1.second * 360 / 60 / 60 / 12) - ) + h1_angle = (t1.hour % 12 * 360 / 12) + (t1.minute * 360 / 60 / 12) + (t1.second * 360 / 60 / 60 / 12) t1 += datetime.timedelta(seconds=1) s2_angle = (t1.second * 360 / 60) or 360 m2_angle = (t1.minute * 360 / 60) + (t1.second * 360 / 60 / 60) or 360 - h2_angle = (t1.hour % 12 * 360 / 12) + (t1.minute * 360 / 60 / 12) + ( - t1.second * 360 / 60 / 60 / 12 - ) or 360 + h2_angle = (t1.hour % 12 * 360 / 12) + (t1.minute * 360 / 60 / 12) + (t1.second * 360 / 60 / 60 / 12) or 360 if s1_angle < m1_angle and s2_angle >= m2_angle: answer += 1 diff --git a/coding_test/programmers/brute_force/number_baseball/test.py b/coding_test/programmers/brute_force/number_baseball/test.py index c1a72de..8d3d12d 100644 --- a/coding_test/programmers/brute_force/number_baseball/test.py +++ b/coding_test/programmers/brute_force/number_baseball/test.py @@ -5,6 +5,4 @@ class TestCase(unittest.TestCase): def test_case_1(self) -> None: - self.assertEqual( - solution([[123, 1, 1], [356, 1, 0], [327, 2, 0], [489, 0, 1]]), 2 - ) + self.assertEqual(solution([[123, 1, 1], [356, 1, 0], [327, 2, 0], [489, 0, 1]]), 2) diff --git a/coding_test/programmers/brute_force/split_electric_grid.py b/coding_test/programmers/brute_force/split_electric_grid.py index 9f00f7b..f5e5c28 100644 --- a/coding_test/programmers/brute_force/split_electric_grid.py +++ b/coding_test/programmers/brute_force/split_electric_grid.py @@ -24,9 +24,6 @@ def solution(n, wires): def test_cases(): - assert ( - solution(9, [[1, 3], [2, 3], [3, 4], [4, 5], [4, 6], [4, 7], [7, 8], [7, 9]]) - == 3 - ) + assert solution(9, [[1, 3], [2, 3], [3, 4], [4, 5], [4, 6], [4, 7], [7, 8], [7, 9]]) == 3 assert solution(4, [[1, 2], [2, 3], [3, 4]]) == 0 assert solution(7, [[1, 2], [2, 7], [3, 7], [3, 4], [4, 5], [6, 7]]) == 1 diff --git a/coding_test/programmers/dfs_bfs/fill_puzzle_failed.py b/coding_test/programmers/dfs_bfs/fill_puzzle_failed.py index 77b1e75..2160dae 100644 --- a/coding_test/programmers/dfs_bfs/fill_puzzle_failed.py +++ b/coding_test/programmers/dfs_bfs/fill_puzzle_failed.py @@ -36,9 +36,7 @@ def extract_polygon(grid, active_value, queue, visited): x, y, cell = queue.popleft() for arrow, (dx, dy, n_cell) in xy_distances.items(): nx, ny = x + dx, y + dy - if (0 > nx or nx >= len(grid) or 0 > ny or ny >= len(grid)) or cell[ - arrow - ] == "1": + if (0 > nx or nx >= len(grid) or 0 > ny or ny >= len(grid)) or cell[arrow] == "1": continue if grid[ny][nx] == active_value: cell = "".join("1" if i == arrow else c for i, c in enumerate(cell)) diff --git a/coding_test/programmers/dfs_bfs/network/test.py b/coding_test/programmers/dfs_bfs/network/test.py index f99466c..79ff15b 100644 --- a/coding_test/programmers/dfs_bfs/network/test.py +++ b/coding_test/programmers/dfs_bfs/network/test.py @@ -8,18 +8,10 @@ def test_case_1(self): self.assertEqual(solution(3, [[1, 1, 0], [1, 1, 0], [0, 0, 1]]), 2) self.assertEqual(solution(3, [[1, 1, 0], [1, 1, 1], [0, 1, 1]]), 1) self.assertEqual(solution(3, [[1, 1, 1], [1, 1, 1], [1, 1, 1]]), 1) - self.assertEqual( - solution(4, [[1, 1, 1, 0], [1, 1, 0, 0], [1, 0, 1, 1], [0, 0, 1, 1]]), 1 - ) - self.assertEqual( - solution(4, [[1, 1, 1, 0], [1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1]]), 1 - ) - self.assertEqual( - solution(4, [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]), 4 - ) - self.assertEqual( - solution(4, [[1, 0, 0, 1], [0, 1, 1, 1], [0, 1, 1, 0], [1, 0, 1, 1]]), 1 - ) + self.assertEqual(solution(4, [[1, 1, 1, 0], [1, 1, 0, 0], [1, 0, 1, 1], [0, 0, 1, 1]]), 1) + self.assertEqual(solution(4, [[1, 1, 1, 0], [1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1]]), 1) + self.assertEqual(solution(4, [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]), 4) + self.assertEqual(solution(4, [[1, 0, 0, 1], [0, 1, 1, 1], [0, 1, 1, 0], [1, 0, 1, 1]]), 1) self.assertEqual( solution( 5, diff --git a/coding_test/programmers/dfs_bfs/pickup_item.py b/coding_test/programmers/dfs_bfs/pickup_item.py index 0d3e012..dc27e24 100644 --- a/coding_test/programmers/dfs_bfs/pickup_item.py +++ b/coding_test/programmers/dfs_bfs/pickup_item.py @@ -32,21 +32,12 @@ def solution(rectangle, character_x, character_y, item_x, item_y): def test_cases(): - assert ( - solution([[1, 1, 7, 4], [3, 2, 5, 5], [4, 3, 6, 9], [2, 6, 8, 8]], 1, 3, 7, 8) - == 17 - ) - assert ( - solution([[1, 1, 8, 4], [2, 2, 4, 9], [3, 6, 9, 8], [6, 3, 7, 7]], 9, 7, 6, 1) - == 11 - ) + assert solution([[1, 1, 7, 4], [3, 2, 5, 5], [4, 3, 6, 9], [2, 6, 8, 8]], 1, 3, 7, 8) == 17 + assert solution([[1, 1, 8, 4], [2, 2, 4, 9], [3, 6, 9, 8], [6, 3, 7, 7]], 9, 7, 6, 1) == 11 assert solution([[1, 1, 5, 7]], 1, 1, 4, 7) == 9 assert solution([[2, 1, 7, 5], [6, 4, 10, 10]], 3, 1, 7, 10) == 15 assert solution([[2, 2, 5, 5], [1, 3, 6, 4], [3, 1, 4, 6]], 1, 4, 6, 3) == 10 - assert ( - solution([[2, 1, 3, 6], [4, 1, 5, 6], [1, 2, 6, 3], [1, 4, 6, 5]], 3, 2, 5, 4) - == 8 - ) + assert solution([[2, 1, 3, 6], [4, 1, 5, 6], [1, 2, 6, 3], [1, 4, 6, 5]], 3, 2, 5, 4) == 8 assert solution([[1, 1, 4, 4], [2, 2, 5, 5], [3, 3, 7, 8]], 1, 1, 5, 3) == 6 assert solution([[1, 1, 2, 2]], 1, 1, 2, 2) == 2 assert solution([[1, 1, 50, 5]], 1, 1, 50, 5) == 53 diff --git a/coding_test/programmers/graph/ranking.py b/coding_test/programmers/graph/ranking.py index ac5f3db..dd0afe5 100644 --- a/coding_test/programmers/graph/ranking.py +++ b/coding_test/programmers/graph/ranking.py @@ -9,9 +9,7 @@ def solution(n, results): loses[loser].update(loses[i]) for winner in loses[i]: wins[winner].update(wins[i]) - return sum( - len(winners) + len(losers) == n - 1 for winners, losers in zip(wins, loses) - ) + return sum(len(winners) + len(losers) == n - 1 for winners, losers in zip(wins, loses)) def test_cases(): diff --git a/coding_test/programmers/hash/album.py b/coding_test/programmers/hash/album.py index cf71420..cefe9b0 100644 --- a/coding_test/programmers/hash/album.py +++ b/coding_test/programmers/hash/album.py @@ -30,6 +30,4 @@ def solution(genres, plays): def test_cases(): - assert solution( - ["classic", "pop", "classic", "classic", "pop"], [500, 600, 150, 800, 2500] - ) == [4, 1, 3, 0] + assert solution(["classic", "pop", "classic", "classic", "pop"], [500, 600, 150, 800, 2500]) == [4, 1, 3, 0] diff --git a/coding_test/programmers/select_dice.py b/coding_test/programmers/select_dice.py index 8bc09e3..54fb195 100644 --- a/coding_test/programmers/select_dice.py +++ b/coding_test/programmers/select_dice.py @@ -4,10 +4,7 @@ def solution(dice): data = { - combi: sorted( - sum(dice[v][k] for k, v in zip(x, combi)) - for x in product(range(6), repeat=len(combi)) - ) + combi: sorted(sum(dice[v][k] for k, v in zip(x, combi)) for x in product(range(6), repeat=len(combi))) for combi in combinations(range(len(dice)), len(dice) // 2) } result = {} @@ -27,9 +24,7 @@ def solution(dice): def test_cases(): - assert solution( - [[1, 2, 3, 4, 5, 6], [3, 3, 3, 3, 4, 4], [1, 3, 3, 4, 4, 4], [1, 1, 4, 4, 5, 5]] - ) == [1, 4] + assert solution([[1, 2, 3, 4, 5, 6], [3, 3, 3, 3, 4, 4], [1, 3, 3, 4, 4, 4], [1, 1, 4, 4, 5, 5]]) == [1, 4] assert solution([[1, 2, 3, 4, 5, 6], [2, 2, 4, 4, 6, 6]]) == [2] assert solution( [ diff --git a/coding_test/programmers/sort/kth_number/solution.py b/coding_test/programmers/sort/kth_number/solution.py index cf73bf2..e807d8c 100644 --- a/coding_test/programmers/sort/kth_number/solution.py +++ b/coding_test/programmers/sort/kth_number/solution.py @@ -6,7 +6,4 @@ def solution(array, commands): - return [ - sorted(array[command[0] - 1 : command[1]])[command[2] - 1] - for command in commands - ] + return [sorted(array[command[0] - 1 : command[1]])[command[2] - 1] for command in commands] diff --git a/coding_test/programmers/stack_queue/truck/test.py b/coding_test/programmers/stack_queue/truck/test.py index a0745d1..081ea82 100644 --- a/coding_test/programmers/stack_queue/truck/test.py +++ b/coding_test/programmers/stack_queue/truck/test.py @@ -5,9 +5,7 @@ class UnitTest(unittest.TestCase): def test_solution(self) -> None: - self.assertEqual( - solution(bridge_length=2, weight=10, truck_weights=[7, 4, 5, 6]), 8 - ) + self.assertEqual(solution(bridge_length=2, weight=10, truck_weights=[7, 4, 5, 6]), 8) self.assertEqual( solution(bridge_length=100, weight=100, truck_weights=[10]), 101, diff --git a/compression/huffman/huffman.py b/compression/huffman/huffman.py index d7e6b03..4052b60 100644 --- a/compression/huffman/huffman.py +++ b/compression/huffman/huffman.py @@ -4,9 +4,7 @@ class Node(object): - def __init__( - self, value: Union[str, None], bitstring=None, left=None, right=None - ) -> None: + def __init__(self, value: Union[str, None], bitstring=None, left=None, right=None) -> None: self.value = value self.bitstring: str = bitstring self.left: Union[Node, None] = left diff --git a/data_structures/graph/adjacency_list/adjacency_list.py b/data_structures/graph/adjacency_list/adjacency_list.py index e9beab3..cb7873d 100644 --- a/data_structures/graph/adjacency_list/adjacency_list.py +++ b/data_structures/graph/adjacency_list/adjacency_list.py @@ -72,9 +72,7 @@ def print_graph(self) -> dict: if current_vertex.adjacency_list is not None: __edge = current_vertex.adjacency_list while __edge is not None: - result[current_vertex.value]["adjacency_list"][ - __edge.target.value - ] = __edge.weight + result[current_vertex.value]["adjacency_list"][__edge.target.value] = __edge.weight __edge = __edge.next current_vertex = current_vertex.next diff --git a/data_structures/graph/adjacency_matrix/adjacency_matrix.py b/data_structures/graph/adjacency_matrix/adjacency_matrix.py index 8828a29..d286e9d 100644 --- a/data_structures/graph/adjacency_matrix/adjacency_matrix.py +++ b/data_structures/graph/adjacency_matrix/adjacency_matrix.py @@ -61,9 +61,7 @@ def print_graph(self) -> dict: for __vertex in self.vertices: result[__vertex.value]["visited"] = __vertex.is_visited - result[__vertex.value]["edges"] = [ - (__vertex.index, target) for target in __vertex.edges - ] + result[__vertex.value]["edges"] = [(__vertex.index, target) for target in __vertex.edges] return result def dfs(self, __vertex: Vertex = None) -> None: diff --git a/data_structures/hash_table/test.py b/data_structures/hash_table/test.py index faf6d29..9955604 100644 --- a/data_structures/hash_table/test.py +++ b/data_structures/hash_table/test.py @@ -68,9 +68,7 @@ def test_quadratic_probing(self) -> None: hash_table.set(14) hash_table.set(3) self.assertEqual(hash_table.size, 11) - self.assertEqual( - hash_table.keys, {0: 0, 2: 2, 3: 14, 4: 4, 6: 6, 8: 8, 9: 3, 10: 10} - ) + self.assertEqual(hash_table.keys, {0: 0, 2: 2, 3: 14, 4: 4, 6: 6, 8: 8, 9: 3, 10: 10}) def test_double_hashing(self) -> None: hash_table = DoubleHashingHashTable(7) diff --git a/data_structures/heap/max_heap.py b/data_structures/heap/max_heap.py index f0bd309..9b446ab 100644 --- a/data_structures/heap/max_heap.py +++ b/data_structures/heap/max_heap.py @@ -27,10 +27,7 @@ def remove_max(self): while left or right: if left and right: - if ( - self.data[current] < self.data[left] - or self.data[current] < self.data[right] - ): + if self.data[current] < self.data[left] or self.data[current] < self.data[right]: if self.data[right] <= self.data[left]: self.__swap(current, left) current = left diff --git a/data_structures/heap/min_heap.py b/data_structures/heap/min_heap.py index 4fd0a82..0c23fc0 100644 --- a/data_structures/heap/min_heap.py +++ b/data_structures/heap/min_heap.py @@ -27,10 +27,7 @@ def remove_min(self): while left or right: if left and right: - if ( - self.data[left] < self.data[current] - or self.data[right] < self.data[current] - ): + if self.data[left] < self.data[current] or self.data[right] < self.data[current]: if self.data[left] <= self.data[right]: self.__swap(current, left) current = left diff --git a/data_structures/queue/circular_queue/circular_queue.py b/data_structures/queue/circular_queue/circular_queue.py index 26eab52..9a803aa 100644 --- a/data_structures/queue/circular_queue/circular_queue.py +++ b/data_structures/queue/circular_queue/circular_queue.py @@ -28,6 +28,4 @@ def is_empty(self) -> bool: @property def is_full(self) -> bool: - return ( - False if self.is_empty else (self.rear + 1) == (self.front + self.capacity) - ) + return False if self.is_empty else (self.rear + 1) == (self.front + self.capacity) diff --git a/data_structures/queue/priority_queue/priority_queue.py b/data_structures/queue/priority_queue/priority_queue.py index 2ad262d..507e4b0 100644 --- a/data_structures/queue/priority_queue/priority_queue.py +++ b/data_structures/queue/priority_queue/priority_queue.py @@ -31,10 +31,7 @@ def dequeue(self): while left or right: if left and right: - if ( - self.data[left][1] < self.data[current][1] - or self.data[right][1] < self.data[current][1] - ): + if self.data[left][1] < self.data[current][1] or self.data[right][1] < self.data[current][1]: if self.data[left][1] <= self.data[right][1]: self.__swap(current, left) current = left diff --git a/data_structures/stack/calculator/infix_to_postfix.py b/data_structures/stack/calculator/infix_to_postfix.py index c21cb05..b08bfe0 100644 --- a/data_structures/stack/calculator/infix_to_postfix.py +++ b/data_structures/stack/calculator/infix_to_postfix.py @@ -36,10 +36,7 @@ def infix_to_postfix(expression: str) -> list: else: if token not in OPERATOR: raise Exception("허용되지 않은 연산자입니다.") - while ( - not operator_stack.is_empty - and OPERATOR[operator_stack.peek()] >= OPERATOR[token] - ): + while not operator_stack.is_empty and OPERATOR[operator_stack.peek()] >= OPERATOR[token]: # 현재 연산자보다 우선순위가 높은 연산자들을 식에 추가 postfix.append(operator_stack.pop()) # 현재 추가되는 연산자가 가장 우선순위가 높은 연산자 diff --git a/data_structures/tree/red_black_tree/red_black_tree.py b/data_structures/tree/red_black_tree/red_black_tree.py index 1f2bc65..16de914 100644 --- a/data_structures/tree/red_black_tree/red_black_tree.py +++ b/data_structures/tree/red_black_tree/red_black_tree.py @@ -169,10 +169,7 @@ def insert(self, value): def remove(self, target): if target := self.search(target): - if ( - target.left == RedBlackTree.empty_node - or target.right == RedBlackTree.empty_node - ): + if target.left == RedBlackTree.empty_node or target.right == RedBlackTree.empty_node: removed = target else: removed = self.get_min(target) @@ -200,10 +197,7 @@ def remove(self, target): successor.parent.color = 1 self.left_rotate(successor.parent) else: - if ( - successor.sibling.left.is_black - and successor.sibling.right.is_black - ): + if successor.sibling.left.is_black and successor.sibling.right.is_black: successor.sibling.color = 1 successor = successor.parent else: diff --git a/dynamic_planning/longest_common_subsequence/simple_lcs.py b/dynamic_planning/longest_common_subsequence/simple_lcs.py index e2a2253..1de644c 100644 --- a/dynamic_planning/longest_common_subsequence/simple_lcs.py +++ b/dynamic_planning/longest_common_subsequence/simple_lcs.py @@ -7,7 +7,5 @@ def simple_lcs(x: str, y: str, i: int, j: int, data: List[List[int]]) -> int: elif x[i - 1] == y[j - 1]: data[i][j] = simple_lcs(x, y, i - 1, j - 1, data) + 1 else: - data[i][j] = max( - simple_lcs(x, y, i - 1, j, data), simple_lcs(x, y, i, j - 1, data) - ) + data[i][j] = max(simple_lcs(x, y, i - 1, j, data), simple_lcs(x, y, i, j - 1, data)) return data[i][j] diff --git a/dynamic_planning/longest_common_subsequence/test.py b/dynamic_planning/longest_common_subsequence/test.py index 3c29087..a82fe75 100644 --- a/dynamic_planning/longest_common_subsequence/test.py +++ b/dynamic_planning/longest_common_subsequence/test.py @@ -10,8 +10,7 @@ def setUp(self) -> None: self.first_string: str = "GOOD MORNING" self.second_string: str = "GUTEN MORGEN" self.result_matrix: List[List[int]] = [ - [0] * (len(self.second_string) + 1) - for _ in range(len(self.first_string) + 1) + [0] * (len(self.second_string) + 1) for _ in range(len(self.first_string) + 1) ] @property @@ -25,10 +24,7 @@ def subsequence(self) -> str: subsequence += self.first_string[m - 1] m -= 1 n -= 1 - elif ( - self.result_matrix[m - 1][n] == current - and self.result_matrix[m][n - 1] < current - ): + elif self.result_matrix[m - 1][n] == current and self.result_matrix[m][n - 1] < current: m -= 1 else: n -= 1 diff --git a/search/text_search/knuth_morris_pratt.py b/search/text_search/knuth_morris_pratt.py index 89ab8ee..4ae79af 100644 --- a/search/text_search/knuth_morris_pratt.py +++ b/search/text_search/knuth_morris_pratt.py @@ -1,9 +1,7 @@ from typing import Dict, Union -def knuth_morris_pratt( - text: str, pattern: str, offset: int = 0 -) -> Dict[str, Union[str, int]]: +def knuth_morris_pratt(text: str, pattern: str, offset: int = 0) -> Dict[str, Union[str, int]]: if offset < 0 or len(text) < offset: raise ValueError diff --git a/search/text_search/native_search.py b/search/text_search/native_search.py index c54d889..fa42556 100644 --- a/search/text_search/native_search.py +++ b/search/text_search/native_search.py @@ -1,9 +1,7 @@ from typing import Dict, Union -def native_search( - text: str, pattern: str, offset: int = 0 -) -> Dict[str, Union[str, int]]: +def native_search(text: str, pattern: str, offset: int = 0) -> Dict[str, Union[str, int]]: if offset < 0 or len(text) < offset: raise ValueError diff --git a/search/text_search/rabin_karp.py b/search/text_search/rabin_karp.py index 70bc6c3..0b83fd3 100644 --- a/search/text_search/rabin_karp.py +++ b/search/text_search/rabin_karp.py @@ -29,9 +29,9 @@ def rabin_karp(text: str, pattern: str, offset: int = 0) -> Dict[str, Union[str, if hash_value is None: hash_value = hashing(text[i : i + len(pattern)]) else: - hash_value = 2 * ( - hash_value - (ord(text[i - 1]) * (2 ** (len(pattern) - 1))) - ) + ord(text[i + len(pattern) - 1]) + hash_value = 2 * (hash_value - (ord(text[i - 1]) * (2 ** (len(pattern) - 1)))) + ord( + text[i + len(pattern) - 1] + ) if hash_value == hash_pattern: result["start"] = i diff --git a/search/text_search/test.py b/search/text_search/test.py index 27f7758..5228866 100644 --- a/search/text_search/test.py +++ b/search/text_search/test.py @@ -13,9 +13,7 @@ def setUp(self) -> None: raise unittest.SkipTest def test_case_1(self) -> None: - self.assertRaises( - ValueError, self.func, text=ascii_lowercase, pattern="lmnop", offset=30 - ) + self.assertRaises(ValueError, self.func, text=ascii_lowercase, pattern="lmnop", offset=30) result = self.func(ascii_lowercase, "lmnop") self.assertEqual( diff --git a/sort/bubble_sort/test.py b/sort/bubble_sort/test.py index 65da939..40f064d 100644 --- a/sort/bubble_sort/test.py +++ b/sort/bubble_sort/test.py @@ -11,6 +11,4 @@ def test_bubble_sort(self) -> None: bubble_sort([8, 9, 4, 1, 5, 6, 7, 2, 3]), [1, 2, 3, 4, 5, 6, 7, 8, 9], ) - self.assertEqual( - bubble_sort([1, 1, 2, 1, 2, 1, 2, 2, 1, 2]), [1, 1, 1, 1, 1, 2, 2, 2, 2, 2] - ) + self.assertEqual(bubble_sort([1, 1, 2, 1, 2, 1, 2, 2, 1, 2]), [1, 1, 1, 1, 1, 2, 2, 2, 2, 2]) diff --git a/sort/quick_sort/test.py b/sort/quick_sort/test.py index b8baf4b..cb7380f 100644 --- a/sort/quick_sort/test.py +++ b/sort/quick_sort/test.py @@ -14,9 +14,7 @@ def setUp(self) -> None: self.sorted = sorted(self.unsorted) def test_quick_sort(self) -> None: - self.assertEqual( - quick_sort(self.unsorted, 0, len(self.unsorted) - 1), self.sorted - ) + self.assertEqual(quick_sort(self.unsorted, 0, len(self.unsorted) - 1), self.sorted) def test_shuffle_quick_sort(self) -> None: self.assertEqual(shuffle_quick_sort(self.unsorted), self.sorted)