• 每日一练 bm3 bm2


    
    /*
     * public class ListNode {
     *   int val;
     *   ListNode next = null;
     * }
     */
    
    public class Solution {
        /**
         * 
         * @param head ListNode类 
         * @param k int整型 
         * @return ListNode类
         */
        public ListNode reverseKGroup (ListNode head, int k) {
            // write code here
            int count=0;
            ListNode cur=head;
            while(cur!=null&&count!=k)
            {cur=cur.next;
             count++;
            }
            cur=reverseKGroup(cur,k);
            
            while(count!=0)
            {
                count--;
                ListNode tmp=head.next;
                head.next=cur;
                cur=head;
                head=tmp;
            }return head;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    在这里插入图片描述在这里插入图片描述在这里插入代码片

    import java.util.*;
    
    /*
     * public class ListNode {
     *   int val;
     *   ListNode next = null;
     * }
     */
    
    public class Solution {
        /**
         * 
         * @param head ListNode类 
         * @param k int整型 
         * @return ListNode类
         */
        public ListNode reverseKGroup (ListNode head, int k) {
            // write code here
            int count=0;
            ListNode cur=head;
            while(cur!=null&&count!=k)
            {cur=cur.next;
             count++;
            }
            cur=reverseKGroup(cur,k);
         if(count==k){
            while(count!=0)
            {
                count--;
                ListNode tmp=head.next;
                head.next=cur;
                cur=head;
                head=tmp;
            }head=cur;
             }return head;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    在这里插入图片描述在这里插入图片描述在这里插入代码片

    import java.util.*;
    
    /*
     * public class ListNode {
     *   int val;
     *   ListNode next = null;
     * }
     */
    
    public class Solution {
        /**
         * 
         * @param head ListNode类 
         * @param k int整型 
         * @return ListNode类
         */
        public ListNode reverseKGroup (ListNode head, int k) {
            // write code here
            int count=0;
            ListNode cur=head;
            while(cur!=null&&count!=k)
            {cur=cur.next;
             count++;
            }
            cur=reverseKGroup(cur,k);
         if(count==k){
            while(count!=0)
            {
                count--;
                ListNode tmp=head.next;
                head.next=cur;
                cur=head;
                head=tmp;
            }head=cur;
             }return head;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    该改 首字母bingying拼音无显示
    该字上面

    import java.util.*;
    
    /*
     * public class ListNode {
     *   int val;
     *   ListNode next = null;
     * }
     */
    
    public class Solution {
        /**
         * 
         * @param head ListNode类 
         * @param k int整型 
         * @return ListNode类
         */
        public ListNode reverseKGroup (ListNode head, int k) {
            // write code here
            int count=0;
            ListNode cur=head;
            while(cur!=null&&count!=k)
            {cur=cur.next;
             count++;
            }
             if(count==k){ cur=reverseKGroup(cur,k);
       
            while(count!=0)
            {
                count--;
                ListNode tmp=head.next;
                head.next=cur;
                cur=head;
                head=tmp;
            }head=cur;
             }return head;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    在这里插入图片描述在这里插入图片描述在这里插入图片描述bm2
    不会了又 直接看答案先

    import java.util.*;
     
    /*
     * public class ListNode {
     *   int val;
     *   ListNode next = null;
     * }
     */
     
    public class Solution {
        /**
         *
         * @param head ListNode类
         * @param m int整型
         * @param n int整型
         * @return ListNode类
         */
        public ListNode reverseBetween (ListNode head, int m, int n) {
            // write code here
       
            ListNode newHead=new ListNode(-1);
            newHead.next=head;
             
            ListNode prev=newHead;
            for(int i=0;i<m-1;i++)
            {
                prev=prev.next;
            }
            ListNode rightNode=prev;
            for(int i=0;i<n-m+1;i++)
            {
                rightNode=rightNode.next;
            }
             
            ListNode leftNode=prev.next;
            ListNode cur=rightNode.next;
             
            prev.next=null;
           rightNode.next=null;
             
            reverseList(leftNode);
             
            prev.next=rightNode;
            leftNode.next=cur;
            return newHead.next;}
     
     private void  reverseList(ListNode head)
     {
         
         ListNode prev=head;
         ListNode cur=null;
         while(prev!=null)
         {ListNode prev_next=prev.next;
         prev.next=cur;
          cur=prev;
         prev=prev_next;    
         }
     }
          
     }
     
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61

    在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入代码片

    import java.util.*;
    
    /*
     * public class ListNode {
     *   int val;
     *   ListNode next = null;
     * }
     */
    
    public class Solution {
        /**
         * 
         * @param head ListNode类 
         * @param m int整型 
         * @param n int整型 
         * @return ListNode
         */
        public ListNode reverseBetween (ListNode head, int m, int n) {
            // write code here
         ListNode NewHead=new ListNode(-1);
          ListNode prev=head;  
            for(int i=0;i<m-1;i++)
            {
                prev=prev.next;
            }
            ListNode rightNode=prev;
            for(int i=0;i<n-m+1;i++)
            {
                rightNode=rightNode.next
            }
            ListNode leftNode=prev.next;
            ListNode cur=rightNode.next;
            reverseList(leftNode);
            prev.next=rightNode;
            leftNode.next=cur; 
            return NewHead.next;
                
        }
        public ListNode reverseList(ListNode head){
            ListNode cur=null;
            ListNode prev=head;
            while(prev!=null)
            {
                ListNode prev_next=prev.next;
                 prev.next=cur;
            cur=prev;
                prev=prev_next;
            }
            return cur;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51

    在这里插入图片描述yinggai应该是逆置函数返回为荣wrong
    在这里插入图片描述区别是啥?void 和listnode
    https://www.baidu.com/baidu?tn=monline_3_dg&ie=utf-8&wd=void+%E5%92%8C+listnode+%E6%9C%89%E5%95%A5%E5%8C%BA%E5%88%AB

    https://www.baidu.com/s?ie=utf-8&f=3&rsv_bp=1&tn=monline_3_dg&wd=public%20void%E6%98%AF%E4%BB%80%E4%B9%88%E6%84%8F%E6%80%9D&oq=void%2520%25E5%2592%258C%2520listnode%2520%25E6%259C%2589%25E5%2595%25A5%25E5%258C%25BA%25E5%2588%25AB&rsv_pq=87cab69a0000423d&rsv_t=32abKsP7ub4JoI48IsmFQWHJxaRUu4p6tLOqQjSXJXBcd%2B3t%2Ba3lGTcnO%2BZ9k14%2FEAJU&rqlang=cn&rsv_enter=1&rsv_dl=ts_1&rsv_sug3=14&rsv_sug1=13&rsv_sug7=101&rsv_sug2=1&rsv_btype=t&prefixsug=public%2520void&rsp=1&inputT=7534&rsv_sug4=18081
    java里public是类的访问修饰符,void 是表示空类型,没有返回数据。
    https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=monline_3_dg&wd=public%20void%20public%20listnode&oq=public%2520void%25E6%2598%25AF%25E4%25BB%2580%25E4%25B9%2588%25E6%2584%258F%25E6%2580%259D&rsv_pq=e6e74dde000107b8&rsv_t=2b6c1PBdGIcDYzEKyWUSw5bfCvROJaS6GnOoRzDZuePGUbyZyGm0qBZO2MhI48TBnYcf&rqlang=cn&rsv_enter=1&rsv_dl=tb&rsv_btype=t&inputT=8892&rsv_sug3=38&rsv_sug1=26&rsv_sug7=100&rsv_sug2=0&prefixsug=public%2520void%2520public%2520listnode&rsp=0&rsv_sug4=9804
    https://www.baidu.com/s?wd=public%20listnode&pn=10&oq=public%20listnode&tn=monline_3_dg&ie=utf-8&rsv_pq=9ccbbb4600018810&rsv_t=1d027Ft0qcVrPKQjFCxDwCB4RQvqKatXMOkpedM6ppW2mFfcn5tIHIVi75vfixqNTHaX
    为什么链表的反转不需要返回值
    返回值是社么什么
    https://m.imooc.com/wenda/detail/337550
    。当然,如果这个方法在执行完之后不需要返回任何数据,返回值类型必须写void关键字,不能空着不写。
    https://blog.csdn.net/weixin_33104731/article/details/114022985
    为什么要定义一个void的返回类型
    https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=monline_3_dg&wd=%20%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E5%AE%9A%E4%B9%89%E4%B8%80%E4%B8%AAvoid%E7%9A%84%E8%BF%94%E5%9B%9E%E7%B1%BB%E5%9E%8B&oq=%25E8%25BF%2594%25E5%259B%259E%25E5%2580%25BC%25E6%2598%25AF%25E4%25BB%2580%25E4%25B9%2588java&rsv_pq=a95851a000001ef1&rsv_t=c9f4sE1ecLCje%2Bd68pG3WqPI5pN0vYbvECznaiUXSKOzmvjtoSes%2BeSKsq0T9wCpkC8J&rqlang=cn&rsv_enter=0&rsv_dl=tb&rsv_btype=t&rsv_sug3=127&rsv_sug1=60&rsv_sug7=100&prefixsug=%2520%25E4%25B8%25BA%25E4%25BB%2580%25E4%25B9%2588%25E8%25A6%2581%25E5%25AE%259A%25E4%25B9%2589%25E4%25B8%2580%25E4%25B8%25AAvoid%25E7%259A%2584%25E8%25BF%2594%25E5%259B%259E%25E7%25B1%25BB%25E5%259E%258B&rsp=0&rsv_sug4=2244
    java
    https://blog.csdn.net/qq_56751933/article/details/120737666
    https://www.likecs.com/show-203713019.html
    https://www.likecs.com/show-203713019.html
    java 为什么要定义一个void 的返回类型 链表
    private是否只能指定void
    https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=monline_3_dg&wd=private%E6%98%AF%E5%90%A6%E5%8F%AA%E8%83%BDvoid&oq=%25E4%25B8%25BA%25E4%25BB%2580%25E4%25B9%2588%25E8%25A6%2581%25E5%25AE%259A%25E4%25B9%2589%25E4%25B8%2580%25E4%25B8%25AAvoid%25E7%259A%2584%25E8%25BF%2594%25E5%259B%259E%25E7%25B1%25BB%25E5%259E%258Bjava%25E9%2593%25BE%25E8%25A1%25A8&rsv_pq=ae007a8400005fb4&rsv_t=dd567YNhk7%2FiPaKWnKdJURhIKWfKNn5MNX0en%2Bzom%2FwfAwnLoVrooqSHy%2BEsKB7pHqdg&rqlang=cn&rsv_enter=0&rsv_dl=tb&rsv_btype=t&inputT=9957&rsv_sug3=175&rsv_sug1=80&rsv_sug7=100&rsv_sug2=0&rsv_sug4=11084
    https://blog.csdn.net/weixin_45105160/article/details/119927792
    问了
    类里面调用私有方法 需要获取私有方法返回值吗
    https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=monline_3_dg&wd=%20%E7%B1%BB%E9%87%8C%E9%9D%A2%E8%B0%83%E7%94%A8%E7%A7%81%E6%9C%89%E6%96%B9%E6%B3%95%20%E9%9C%80%E8%A6%81%E8%8E%B7%E5%8F%96%E7%A7%81%E6%9C%89%E6%96%B9%E6%B3%95%E8%BF%94%E5%9B%9E%E5%80%BC%E5%90%97&oq=private%25E6%2598%25AF%25E5%2590%25A6%25E5%258F%25AA%25E8%2583%25BDvoid&rsv_pq=8456b57800012f29&rsv_t=6d23lh%2F8psvbOxgGZ7E%2BSe9N0iEoXvdE4v7sNpPdwcon6Jt%2F4rvU9MxVyv7Ufs1ykxey&rqlang=cn&rsv_enter=0&rsv_dl=tb&rsv_btype=t&rsv_sug3=178&rsv_sug1=83&rsv_sug7=100&prefixsug=%2520%25E7%25B1%25BB%25E9%2587%258C%25E9%259D%25A2%25E8%25B0%2583%25E7%2594%25A8%25E7%25A7%2581%25E6%259C%2589%25E6%2596%25B9%25E6%25B3%2595%2520%25E9%259C%2580%25E8%25A6%2581%25E8%258E%25B7%25E5%258F%2596%25E7%25A7%2581%25E6%259C%2589%25E6%2596%25B9%25E6%25B3%2595%25E8%25BF%2594%25E5%259B%259E%25E5%2580%25BC%25E5%2590%2597&rsp=0&rsv_sug4=3718
    在这里插入图片描述在这里插入图片描述在这里插入代码片

    import java.util.*;
    
    /*
     * public class ListNode {
     *   int val;
     *   ListNode next = null;
     * }
     */
    
    public class Solution {
        /**
         * 
         * @param head ListNode类 
         * @param m int整型 
         * @param n int整型 
         * @return ListNode
         */
        public ListNode reverseBetween (ListNode head, int m, int n) {
            // write code here
         ListNode NewHead=new ListNode(-1);
          ListNode prev=head;  
            for(int i=0;i<m-1;i++)
            {
                prev=prev.next;
            }
            ListNode rightNode=prev;
            for(int i=0;i<n-m+1;i++)
            {
                rightNode=rightNode.next;
            }
            ListNode leftNode=prev.next;
            ListNode cur=rightNode.next;
            prev.next=null;
            rightNode.next=null;
            reverseList(leftNode);
            prev.next=rightNode;
            leftNode.next=cur; 
            return NewHead.next;
                
        }
        public void reverseList(ListNode head){
            ListNode cur=null;
            ListNode prev=head;
            while(prev!=null)
            {
                ListNode prev_next=prev.next;
                 prev.next=cur;
            cur=prev;
                prev=prev_next;
            }
           
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53

    在这里插入图片描述在这里插入代码片

    import java.util.*;
    
    /*
     * public class ListNode {
     *   int val;
     *   ListNode next = null;
     * }
     */
    
    public class Solution {
        /**
         * 
         * @param head ListNode类 
         * @param m int整型 
         * @param n int整型 
         * @return ListNode
         */
        public ListNode reverseBetween (ListNode head, int m, int n) {
            // write code here
         ListNode NewHead=new ListNode(-1);
            NewHead.next=head;
          ListNode prev=head;  
            for(int i=0;i<m-1;i++)
            {
                prev=prev.next;
            }
            ListNode rightNode=prev;
            for(int i=0;i<n-m+1;i++)
            {
                rightNode=rightNode.next;
            }
            ListNode leftNode=prev.next;
            ListNode cur=rightNode.next;
            prev.next=null;
            rightNode.next=null;
            reverseList(leftNode);
            prev.next=rightNode;
            leftNode.next=cur; 
            return NewHead.next;
                
        }
        public void reverseList(ListNode head){
            ListNode cur=null;
            ListNode prev=head;
            while(prev!=null)
            {
                ListNode prev_next=prev.next;
                 prev.next=cur;
            cur=prev;
                prev=prev_next;
            }
           
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54

    在这里插入图片描述在这里插入代码片

    import java.util.*;
    
    /*
     * public class ListNode {
     *   int val;
     *   ListNode next = null;
     * }
     */
    
    public class Solution {
        /**
         * 
         * @param head ListNode类 
         * @param m int整型 
         * @param n int整型 
         * @return ListNode
         */
        public ListNode reverseBetween (ListNode head, int m, int n) {
            // write code here
         ListNode NewHead=new ListNode(-1);
            NewHead.next=head;
          ListNode prev=NewHead;  
            for(int i=0;i<m-1;i++)
            {
                prev=prev.next;
            }
            ListNode rightNode=prev;
            for(int i=0;i<n-m+1;i++)
            {
                rightNode=rightNode.next;
            }
            ListNode leftNode=prev.next;
            ListNode cur=rightNode.next;
            prev.next=null;
            rightNode.next=null;
            reverseList(leftNode);
            prev.next=rightNode;
            leftNode.next=cur; 
            return NewHead.next;
                
        }
        public void reverseList(ListNode head){
            ListNode cur=null;
            ListNode prev=head;
            while(prev!=null)
            {
                ListNode prev_next=prev.next;
                 prev.next=cur;
            cur=prev;
                prev=prev_next;
            }
           
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
  • 相关阅读:
    Docker 安装 Nginx 容器 (完整详细版)
    scratch小老鼠偷面包 电子学会图形化编程scratch等级考试二级真题和答案解析2022年9月
    RabbitMQ教程
    React render方法的原理?在什么时候会被触发?
    使用百度的长文本转语音API时无法下载.MP3文件
    Python中两种网络编程方式:Socket和HTTP协议
    Vue路由 replace属性 控制浏览记录不能前进或后退
    图像处理之理想带阻滤波器、巴特沃斯带阻滤波器和高斯带阻滤波器的matlab实现去噪
    机器学习案例(七):产品需求预测
    Java打印输出:8x8x
  • 原文地址:https://blog.csdn.net/czhc1140075663/article/details/126297497