leetcode new problems

This commit is contained in:
2026-02-11 14:48:41 +05:30
parent 192ce44a81
commit 0f52d46c67
29 changed files with 658 additions and 5 deletions
View File
+26
View File
@@ -0,0 +1,26 @@
ListNode* removeNthFromEnd(ListNode* head, int n){
if(head == nullptr) return head;
ListNode* temp = head;
int count = 0;
while(temp!=nullptr) {
count++;
temp = temp->next;
}
if(n==count) {
ListNode* newHead = head->next;
delete head;
return newHead;
}
temp = head;
for(int i = 1; i<(count-n);i++){
temp = temp->next;
}
ListNode* nodeToDelete = temp->next;
temp->next = nodeToDelete->next;
delete nodeToDelete;
return head;
}
//n == count is when removal node is head
//count-n just goes to one node before the removal node