Reverse A Linked List HackerRank

 public static SinglyLinkedListNode reverse(SinglyLinkedListNode llist) {

            SinglyLinkedListNode temp=llist;
            Stack<Integer> stack=new Stack<Integer>();
            while(temp!=null){
                stack.push(temp.data);
                temp=temp.next;
            }
            temp=llist;
            while(!stack.isEmpty()){
                temp.data=stack.pop();
                temp=temp.next;
            }
            
            return llist;
            
            
            
                    // Write your code here

    }


Comments

Popular posts from this blog

Java Date And Time HackerRank

Recursive Sequence Geeks For Geeks Problem Of The Day 12-02-2024

Minimum Indices HackerEarth