iT邦幫忙

2025 iThome 鐵人賽

DAY 25
0
自我挑戰組

leetcode系列 第 25

leetcode 25. Reverse Nodes in k-Group

  • 分享至 

  • xImage
  •  

題目:
Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list.

k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is.

You may not alter the values in the list's nodes, only nodes themselves may be changed.
給定一個鍊錶的,一次head反轉列表的節點,並傳回修改後的列表。k

k是一個正整數,且小於或等於鍊錶的長度。如果節點數不是 的倍數k,則剩餘的節點最終應保持原樣。

您可能無法變更清單節點中的值,只能變更節點本身。
https://ithelp.ithome.com.tw/upload/images/20251009/20169340goXQMCZ45n.png

https://ithelp.ithome.com.tw/upload/images/20251009/20169340z9minALd9M.png
https://ithelp.ithome.com.tw/upload/images/20251009/201693409zZ0WLwO0x.png


上一篇
leetcode 24. Swap Nodes in Pairs
下一篇
leetcode 26. Remove Duplicates from Sorted Array
系列文
leetcode30
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言