Advertisement
enigmjoe

Big O week 3 day 5 p1

Sep 1st, 2023
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.* ;
  3.  
  4. /****************************************************************
  5.  
  6. Following is the class structure of the Node class:
  7.  
  8. class Node
  9. {
  10. public:
  11. int data;
  12. Node *next;
  13. Node(int data)
  14. {
  15. this->data = data;
  16. this->next = NULL;
  17. }
  18. };
  19.  
  20. *****************************************************************/
  21.  
  22. public class Solution {
  23. public static Node getListAfterReverseOperation(Node head, int n, int b[]) {
  24. Node prev = head , tmp = head;
  25. for(int i = 0; i < n; i++){
  26. int lol = b[i];
  27. ArrayList<Integer> a = new ArrayList<>();
  28. while(lol-- > 0 && tmp != null){
  29. a.add(tmp.data);
  30. tmp = tmp.next;
  31. }
  32. Collections.reverse(a);
  33. for(int j : a){
  34. prev.data = j;
  35. prev = prev.next;
  36. }
  37. }
  38. return head;
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement