-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathsolution.cpp
More file actions
32 lines (30 loc) · 732 Bytes
/
solution.cpp
File metadata and controls
32 lines (30 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
Problem : https://www.hackerrank.com/challenges/delete-a-node-from-a-linked-list/problem
C++ 14
Approach :
We simply need to iterate the linked list and then remove an element by adjusting the node pointers
Time Complexity : O(n)
Space Complexity : O(1)
*/
/*
Delete Node at a given position in a linked list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
Node* Delete(Node *head, int position)
{
// Complete this method
if(position == 0){
return head->next;
}
else{
head->next = Delete(head->next,position-1);
return head;
}
// This is a "method-only" submission.
// You only need to complete this method
}