Absolute Value
Easy · rating 800 · math
Read an integer n. Print its absolute value.
Editorial
Absolute Value returns a number's magnitude without its sign — negate it when negative, otherwise leave it. The built-in abs is the idiomatic choice.
print(n if n >= 0 else -n)Complexity
Time: O(1). Space: O(1).