#Can anyone fact check to understand my code's time complexity which was genearated by AI

1 messages · Page 1 of 1 (latest)

fleet coyote
hollow nebulaBOT
#

This post has been reserved for your question.

Hey @fleet coyote! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

fleet coyote
#

My Solution


 List<NestedInteger> nestedList;
    List<Integer> flattenedList = new ArrayList<>();
    int count = 0;
    int returnValue = 0;

    public NestedIterator(List<NestedInteger> nestedList) {
        this.nestedList = nestedList;
        this.flatAllLists();

    }

    @Override
    public Integer next() {
        int c = count-1;
        return this.flattenedList.get(c);
    }

    @Override
    public boolean hasNext() {
        if(count == this.flattenedList.size()){
            return false;
        }
        count++;
        return true;

    }

    private void flatAllLists() {
        for (int i = 0; i < this.nestedList.size(); i++) {
            NestedInteger nestedInteger = this.nestedList.get(i);
            if (nestedInteger.isInteger()) {
                this.flattenedList.add(nestedInteger.getInteger());
            } else {
                readNestedIntegers(nestedInteger);
            }
        }
    }

    private void readNestedIntegers(NestedInteger nestedInteger) {
        List<NestedInteger> nestedIntegerList = nestedInteger.getList();
        for (NestedInteger nttt : nestedIntegerList
        ) {
            if (nttt.isInteger()) {
                this.flattenedList.add(nttt.getInteger());
            } else {
                readNestedIntegers(nttt);
            }
        }
    }
#

Also critisize the code