0% completed
How would you change the code if you have the remaining sublist values shouldn't...
Donald
Feb 24, 2022
How would you change the code if you have the remaining sublist values shouldn't be changed? ie. instead of 8 -> 7 you leave it at 7 -> 8
3
0
Comments
Perry Robinson4 years ago
Please show how to modify solution so that if a group does not fit within k, it does not get modified. Similar to leetcode 25.
SeungJin Kim4 years ago
Would also like to know
SeungJin Kim4 years ago
temp = current should_end = False for i in range(k): if not temp: should_end = True break temp = temp.next if should_end == True: break
I added this piece of check just before we do the reverse sublist and the answer is accepted for leetcode 25
Kenny Le3 years ago
might not be the most efficient way, but you can first check that a reversal can be completed or not.
java solution, add this for loop before the reversing for loop
ListNode temp = curr; for(int i = 0; i < k; i++){ if(temp == null){ return head; } else{ temp = temp.ne...