Skip to content

Commit 0e64c48

Browse files
authored
Update program.cpp
1 parent f71d41b commit 0e64c48

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

swap_nodes_in_LL/program.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
ListNode *ptr1 = head, *ptr2 = head, *kth = NULL;
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* ListNode *next;
6+
* ListNode() : val(0), next(nullptr) {}
7+
* ListNode(int x) : val(x), next(nullptr) {}
8+
* ListNode(int x, ListNode *next) : val(x), next(next) {}
9+
* };
10+
*/
11+
class Solution {
12+
public:
13+
ListNode* swapNodes(ListNode* head, int k)
14+
{
15+
ListNode *ptr1 = head, *ptr2 = head, *kth = NULL;
216
while (--k)
317
ptr1 = ptr1->next;
418

@@ -11,3 +25,5 @@ ListNode *ptr1 = head, *ptr2 = head, *kth = NULL;
1125
}
1226
swap(ptr2->val, kth->val);
1327
return head;
28+
}
29+
};

0 commit comments

Comments
 (0)