Is this bad practice? Why don't I see anyone else doing this?


  • -1
    M
    public class Vector2D {
        private List<Integer> list;
        
        public Vector2D(List<List<Integer>> vec2d) {
            list = new ArrayList<>();
            for(int i = 0; i < vec2d.size(); i++){
                for(int j = 0; j < vec2d.get(i).size(); j++){
                    list.add(vec2d.get(i).get(j));
                }
            }
        }
    
        public int next() {
            int ret = list.get(0);
            list.remove(0);
            return ret;
        }
    
        public boolean hasNext() {
            return !list.isEmpty();
        }
    }

Log in to reply
 

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