From 5e1aa3387d1c5cc9a6b338c98d409bf184adcb54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=80=D1=8C=D1=8F=20=D0=A2=D0=BE=D1=80=D0=B3?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0?= Date: Tue, 9 Dec 2025 02:58:28 +0300 Subject: [PATCH] Added func Reverse lexicographic comparison --- src/intro_1/reverse_lexicographic_compare.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/intro_1/reverse_lexicographic_compare.py diff --git a/src/intro_1/reverse_lexicographic_compare.py b/src/intro_1/reverse_lexicographic_compare.py new file mode 100644 index 0000000..f29b865 --- /dev/null +++ b/src/intro_1/reverse_lexicographic_compare.py @@ -0,0 +1,17 @@ +def reverse_compare(str_1, str_2): + len_1 = len(str_1) + len_2 = len(str_2) + + for i in range(min(len_1, len_2)): + if str_1[i] > str_2[i]: + return 2 # str_2 > str_1 + if str_2[i] > str_1[i]: + return 1 # str_1 > str_2 + + if len_1 > len_2: + return 1 + + if len_2 > len_1: + return 2 + + return 0 # str_1 == str_2