Super short solution (also beat 97%), why never posted before...am I wrong?


  • 0
    H

    Why has no one posted this super short solution, because of the mentioned follow up for iterators or something?

    If there is anything wrong with my solution please point out. Thanks!

    public class Vector2D {
        int index = 0;
        ArrayList<Integer> rst = new ArrayList<Integer>();
        public Vector2D(List<List<Integer>> vec2d) {
            for (List<Integer> list : vec2d) rst.addAll(list);
        }
    
        public int next() {
            return rst.get(index++);
        }
    
        public boolean hasNext() {
            return index < rst.size();
        }
    }

  • 0

    Why has no one posted this super short solution

    I can't speak for everyone, but the reason I myself didn't post that before probably is that it wasn't short enough for me. (Here's mine.)

    Also, most people probably agree that iterators shouldn't copy the data.


  • 0
    V

    Also, most people probably agree that iterators shouldn't copy the data.

    agree


  • 0
    H

    I see... Thanks for the comment! Your solutions are great.


  • 0
    H

    Thanks Vincent. Now I think so too.


  • 0
    Y
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.