From ed633c85b7608ed84558f8b584f639dd8b61fe9f Mon Sep 17 00:00:00 2001 From: mhrooz Date: Sun, 16 Jun 2024 16:21:09 +0200 Subject: [PATCH] 92 list not diffcult --- 92-240616-pass/main.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 92-240616-pass/main.py diff --git a/92-240616-pass/main.py b/92-240616-pass/main.py new file mode 100644 index 0000000..d2310c9 --- /dev/null +++ b/92-240616-pass/main.py @@ -0,0 +1,25 @@ +class ListNode: + def __init__(self, val = 0, next = None): + self.val = val + self.next = next +class Solution: + def reverseBetween(self, head: Optional[ListNode], left: int, right: int) -> Optional[ListNode]: + cnt = 0 + l = [] + true_head = ListNode() + true_head.next = head + true_end = ListNode() + cur = head + while cur.next != None: + cur = cur.next + cur.next = true_end + cur = true_head + + while cur != None: + if cnt >= left - 1 and cnt <= right + 1: + l.append(cur) + cur = cur.next + cnt += 1 + for ind in range(len(l), 0, -1): + l[ind].next = l[ind-1] + \ No newline at end of file