Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LinkedList<Integer> list = new LinkedList<>(); //add 0 1 2 3 4 5 6
- Iterator<Integer> it = list.iterator(); // so this is used with collections
- // we need to remove the k item from the list if k = 3 we remove list[2] after list[5] after [1]
- //circular?
- // makes it go k times to the next item in the list
- while (count < k) {
- while (it.hasNext() && count < k) { // 0 ||
- it.next(); //0 1 2 ||
- count++; //1 2 3 == 3 ||
- }
- it.remove(); // remove list[2] ||
- //remove k=3
- //if count < k we need to restart the it from 0 (make a new it with same list?)
- // restart counter to 0 always until , work until list size is 1 , output only 1 number
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement