MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / swap

Function swap

data_structures/binary_tree/lowest_common_ancestor.py:9–24  ·  view source on GitHub ↗

Return a tuple (b, a) when given two integers a and b >>> swap(2,3) (3, 2) >>> swap(3,4) (4, 3) >>> swap(67, 12) (12, 67) >>> swap(3,-4) (-4, 3)

(a: int, b: int)

Source from the content-addressed store, hash-verified

7
8
9def swap(a: int, b: int) -> tuple[int, int]:
10 """
11 Return a tuple (b, a) when given two integers a and b
12 >>> swap(2,3)
13 (3, 2)
14 >>> swap(3,4)
15 (4, 3)
16 >>> swap(67, 12)
17 (12, 67)
18 >>> swap(3,-4)
19 (-4, 3)
20 """
21 a ^= b
22 b ^= a
23 a ^= b
24 return a, b
25
26
27def create_sparse(max_node: int, parent: list[list[int]]) -> list[list[int]]:

Callers 1

lowest_common_ancestorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected