'Reverse a sublist of a linked list
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode reverseBetween(ListNode head, int left, int right) {
if(head.next==null){
return head;
}
if(left==right){
return head;
}
ListNode dummy=new ListNode();
dummy.next=head;
ListNode prevNode=dummy;
ListNode currNode=head;
for(int i=1;i<left;i++){
prevNode=currNode;
currNode=currNode.next;
}
for(int i=1;i<=(right-left);i++){
ListNode nextNode=currNode.next;
prevNode.next=nextNode;``
currNode.next=nextNode.next;
nextNode.next=prevNode.next;
}
return dummy.next;
}}
It is a question of reversing sublist from Leetcode.Can anyone please tell me why it is showing "found cycle in code"??I dont know why it showing this error.Please explain.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
