package question;/*** @author Roderland* @since 1.0*/public class Question92 {public static void main(String[] args) {System.out.println(new Question92().reverseBetween(new ListNode(5), 1, 1).val);}public ListNode reverseBetween(ListNode head, int left, int right) {ListNode slow = head;ListNode fast = head;for (int i = 0; i < right - left; i++) {fast = fast.next;}ListNode a = null;for (int i = 1; i < left; i++) {a = slow;slow = slow.next;fast = fast.next;}ListNode b = fast.next;ListNode pre = a;ListNode cur = slow;while (cur != b) {ListNode next = cur.next;cur.next = pre;pre = cur;cur = next;}if (slow != null) slow.next = b;if (a != null) a.next = pre;else head = fast;return head;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。