_341_nested_interger

package
v0.0.0-...-a601ee6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2021 License: MIT Imports: 0 Imported by: 0

README

  1. 扁平化嵌套列表迭代器 medium 给你一个嵌套的整型列表。请你设计一个迭代器,使其能够遍历这个整型列表中的所有整数。

列表中的每一项或者为一个整数,或者是另一个列表。其中列表的元素也可能是整数或是其他列表。

示例 1:

输入: [[1,1],2,[1,1]]
输出: [1,1,2,1,1]
解释: 通过重复调用 next 直到 hasNext 返回 false,next 返回的元素的顺序应该是: [1,1,2,1,1]。
示例 2:
输入: [1,[4,[6]]]
输出: [1,4,6]
解释: 通过重复调用 next 直到 hasNext 返回 false,next 返回的元素的顺序应该是: [1,4,6]。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NestedInteger

type NestedInteger struct {
}

This is the interface that allows for creating nested lists. You should not implement it, or speculate about its implementation

func (*NestedInteger) Add

func (this *NestedInteger) Add(elem NestedInteger)

Set this NestedInteger to hold a nested list and adds a nested integer to it.

func (NestedInteger) GetInteger

func (this NestedInteger) GetInteger() int

Return the single integer that this NestedInteger holds, if it holds a single integer The result is undefined if this NestedInteger holds a nested list So before calling this method, you should have a check

func (NestedInteger) GetList

func (this NestedInteger) GetList() []*NestedInteger

Return the nested list that this NestedInteger holds, if it holds a nested list The list length is zero if this NestedInteger holds a single integer You can access NestedInteger's List element directly if you want to modify it

func (NestedInteger) IsInteger

func (this NestedInteger) IsInteger() bool

Return true if this NestedInteger holds a single integer, rather than a nested list.

func (*NestedInteger) SetInteger

func (n *NestedInteger) SetInteger(value int)

Set this NestedInteger to hold a single integer.

type NestedIterator

type NestedIterator struct {
	Data []*NestedInteger
}

func Constructor

func Constructor(nestedList []*NestedInteger) *NestedIterator

func (*NestedIterator) HasNext

func (this *NestedIterator) HasNext() bool

func (*NestedIterator) Next

func (this *NestedIterator) Next() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL