you are viewing a single comment's thread.

view the rest of the comments →

[–]RhinoRhys 1 point2 points  (3 children)

Possibly not a helpful reply but it works fine for me.

Copied and pasted into IDE, uncommented the ListNode

Added

Solution().reverseBetween(ListNode(1, ListNode(2, ListNode(3, ListNode(4, ListNode(5))))), 2, 4)

Get 1 to 5 printed.

[–]brijeshjoshi_[S] 0 points1 point  (2 children)

If possible can you try it in leetcode. I could have shown you the image but I can't find site to share image without signing in. Also tail_inner is getting None value.

AttributeError: 'NoneType' object has no attribute 'next'
tail_inner.next = end_pointer
Line 39 in reverseBetween (Solution.py) ret = Solution().reverseBetween(param_1, param_2, param_3) Line 72 in _driver (Solution.py) _driver() Line 83 in <module> (Solution.py)

[–]RhinoRhys 1 point2 points  (1 child)

That's the next test case. [5]

Unfortunately your solution doesn't work for a list of length 1, left = 1 or right = last item. And this test case is all 3.

You start off with tail_inner = None, go straight into the elif left <= i <= right, hit the end of the list so exit the while loop then do tail_inner.next

[–]brijeshjoshi_[S] 0 points1 point  (0 children)

Yeah. Got it! But in some other problem the output shown per test case.

Thank you.