提示文章写完后目录可以自动生成如何生成可参考右边的帮助文档文章目录K 个一组翻转链表题目分析:数K个数,返回链表反转总逻辑代码K 个一组翻转链表https://leetcode.com/problems/reverse-nodes-in-k-group/题目分析:数K个数,返回publicstaticListNodegetKGroupEnd(ListNodestart,intk){while(--k!0start!null){startstart.next;}returnstart;}链表反转publicstaticvoidreverse(ListNodestart,ListNodeend){endend.next;ListNodeprenull;ListNodecurstart;ListNodenextnull;while(cur!end){nextcur.next;cur.nextpre;precur;curnext;}start.nextend;}总逻辑代码// 测试链接https://leetcode.com/problems/reverse-nodes-in-k-group/publicclassCode04_ReverseNodesInKGroup{// 不要提交这个类publicstaticclassListNode{publicintval;publicListNodenext;}publicstaticListNodereverseKGroup(ListNodehead,intk){ListNodestarthead;ListNodeendgetKGroupEnd(start,k);if(endnull){returnhead;}// 第一组凑齐了headend;reverse(start,end);// 上一组的结尾节点ListNodelastEndstart;while(lastEnd.next!null){startlastEnd.next;endgetKGroupEnd(start,k);if(endnull){returnhead;}reverse(start,end);lastEnd.nextend;lastEndstart;}returnhead;}publicstaticListNodegetKGroupEnd(ListNodestart,intk){while(--k!0start!null){startstart.next;}returnstart;}publicstaticvoidreverse(ListNodestart,ListNodeend){endend.next;ListNodeprenull;ListNodecurstart;ListNodenextnull;while(cur!end){nextcur.next;cur.nextpre;precur;curnext;}start.nextend;}}