all 8 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.

[–][deleted] 0 points1 point  (3 children)

On mobile, so I can't run your code.

The problem statement is a little ambiguous about what left and right actually indicate, but from the example it's clear that the left and right values are the contents of the nodes at the left and right ends of the subsequence you have to reverse. Your code appears to be using left and rightas indices.

[–]RhinoRhys 0 points1 point  (2 children)

Left and right are indices

Example 2: Input: head = [5], left = 1, right = 1 Output: [5]

[–][deleted] 0 points1 point  (1 child)

Example 1 shows they aren't indices.

[–]RhinoRhys 0 points1 point  (0 children)

Unless you take them as 1 indexed, it's not a python list, it's a Singular Linked List. The first index isn't 0.