Advertisement
ahmed19981973

Untitled

Dec 31st, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.08 KB | None | 0 0
  1.  static int poisonousPlants(int[] p) {
  2.         int i=1;//counter off days
  3.         LinkedList<Integer> alive1 =new LinkedList<>();
  4.         LinkedList<Integer> alive2 =new LinkedList<>();
  5.         LinkedList<Integer>pfull=alive1;
  6.         LinkedList<Integer>pEmpty=alive2;
  7.         for (int plant: p) { pfull.push(plant); }//now the element exist at list
  8.         int presize=0;
  9.         for ( i=0; presize!=pfull.size(); i++) {
  10.             pEmpty.push(pfull.get(0));//the first  element don't have left so it remains always
  11.             for (int j = 1; j <pfull.size() ; j++) {
  12.                 if (pfull.get(j) < pfull.get(j - 1)) {
  13.                     pEmpty.push(pfull.get(j));
  14.                 }
  15.             }
  16.                 System.out.println("hi");
  17.                 System.out.println(pfull.size());
  18.                 presize=pfull.size();
  19.                 LinkedList<Integer> old=pEmpty;
  20.                 pfull.clear();
  21.                 pEmpty=pfull;
  22.                 pfull=old;
  23.                 System.out.println("hello");
  24.  
  25.         }
  26.         System.out.println("ajksj");
  27. return i;
  28.  
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement