Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.* ;
- /****************************************************************
- Following is the class structure of the Node class:
- class Node
- {
- public:
- int data;
- Node *next;
- Node(int data)
- {
- this->data = data;
- this->next = NULL;
- }
- };
- *****************************************************************/
- public class Solution {
- public static Node getListAfterReverseOperation(Node head, int n, int b[]) {
- Node prev = head , tmp = head;
- for(int i = 0; i < n; i++){
- int lol = b[i];
- ArrayList<Integer> a = new ArrayList<>();
- while(lol-- > 0 && tmp != null){
- a.add(tmp.data);
- tmp = tmp.next;
- }
- Collections.reverse(a);
- for(int j : a){
- prev.data = j;
- prev = prev.next;
- }
- }
- return head;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement