力扣 链表二

400-110=290
动态规划,还有栈

搞定之后,大约是130
还有270道、、一天两道外加上复盘、、

JVM、 ~~~~~~~~~
mysql、
微服务 ~~~~~~~~~~~~~图灵
Spring、、

八股总结、、、、
项目、底层源码、、、、

92、反转链表二


class Solution {
    public ListNode reverseBetween(ListNode head, int left, int right) {
        if(head==null || head.next==null) return head;
        ListNode preHead=new ListNode(-1,head),pre=preHead,cur=head,temp=head,node1=head;
        int count=0;
        while (cur!=null){
            count++;
            if(count==left){
                node1=cur;
                while (count<=right){
                    temp=cur.next;
                    cur.next=pre.next;
                    pre.next=cur;
                    cur=temp;
                    count++;
                }
                node1.next=temp;
                if(left==1) return preHead.next;
                return head;
            }else {
                pre=cur;
                cur=cur.next;
            }
        }
        return head;
    }
}

206. 反转链表

labuladong 题解思路

class Solution {
    public ListNode reverseList(ListNode head) {
        ListNode preHead=new ListNode(-1,null),pre=preHead,cur=head,temp=head;
        while (cur!=null){
            temp=cur.next;
            cur.next=pre.next;
            pre.next=cur;
            cur=temp;
        }
        return pre.next;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容