File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
dsa-solutions/lc-solutions/2500 - 3000 Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
id : insert-greatest-common-divisors-in-linked-list
3
- title:Insert Greatest Common Divisors in Linked List
3
+ title : Insert Greatest Common Divisors in Linked List
4
4
sidebar_label : 2807 Insert Greatest Common Divisors in Linked List
5
5
tags :
6
6
- Linked List
@@ -64,17 +64,17 @@ public:
64
64
vector<int >a,b;
65
65
ListNode* k=head;
66
66
while(head!=NULL){
67
- a.push_back(head->val);
67
+ a.push_back(head->val); // store each node value of the given linked list
68
68
head=head->next;
69
69
}
70
- for(int i=0;i<a.size()-1;i++){
70
+ for(int i=0;i<a.size()-1;i++){ //to store gratest common divisors(gcd) of adjacent pairs
71
71
int p=__ gcd(a[ i] ,a[ i+1] );
72
72
b.push_back(p);
73
73
}
74
74
head=k;
75
75
int i=0;
76
- while(k!=NULL && k->next!=NULL){
77
- ListNode* temp=new ListNode(b[ i] );
76
+ while(k!=NULL && k->next!=NULL){ // inserting gcd between the linked list
77
+ ListNode* temp=new ListNode(b[ i] );
78
78
ListNode* next=k->next;
79
79
i++;
80
80
k->next=temp;
You can’t perform that action at this time.
0 commit comments