本文整理汇总了C++中NestedInteger::getList方法的典型用法代码示例。如果您正苦于以下问题:C++ NestedInteger::getList方法的具体用法?C++ NestedInteger::getList怎么用?C++ NestedInteger::getList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NestedInteger
的用法示例。
在下文中一共展示了NestedInteger::getList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hasNext
bool hasNext() {
while (!s.empty()) {
NestedInteger t = s.top();
if (t.isInteger()) return true;
s.pop();
for (int i = t.getList().size() - 1; i >= 0; --i) {
s.push(t.getList()[i]);
}
}
return false;
}
示例2: hasNext
bool hasNext() {
if (record.empty())
return false;
while (record.size() && record.top().isInteger() == false) {
NestedInteger top = record.top();
record.pop();
for (int i = top.getList().size()-1; i >= 0; i--) {
record.push(top.getList()[i]);
}
}
return record.empty()? false : true;
}
示例3: hasNext
bool hasNext() {
while (!sk.empty() ) {
NestedInteger cur = sk.top();
if ( cur.isInteger() ) {return true;}
else {sk.pop(); }
int sz_cur = cur.getList().size();
for (int i = sz_cur - 1; i >= 0; i--) {
sk.push(cur.getList()[i]);
}
}
return false;
}
示例4: helper
void helper(NestedInteger num){
if(num.isInteger())
res.push_back(num.getInteger());
else{
for(auto n : num.getList())
helper(n);
}
}
示例5: getSum
int getSum(NestedInteger ni, int level) {
int res = 0;
if (ni.isInteger()) return level * ni.getInteger();
for (auto a : ni.getList()) {
res += getSum(a, level + 1);
}
return res;
}
示例6: flatten
void flatten(NestedInteger lariat) {
if (lariat.isInteger())
vec.push_back(lariat.getInteger());
else {
for (NestedInteger KillerBee : lariat.getList())
flatten(KillerBee);
}
}
示例7: dfs
void dfs(NestedInteger& ni) {
if (ni.isInteger())
container.push_back(ni.getInteger());
else {
vector<NestedInteger> nestedList = ni.getList();
for (int i = 0; i < nestedList.size(); ++i)
dfs(nestedList[i]);
}
}
示例8: getValue
void getValue(NestedInteger& a, vector<int>& v, int lvl) {
if (a.isInteger()) {
v[lvl] += (v.size() - lvl) * a.getInteger();
}
else {
for (auto b: a.getList()) {
getValue(b, v, lvl + 1);
}
}
}
示例9: configNums
void configNums(const NestedInteger i,vector<int>& nums){
if(i.isInteger()){
nums.push_back(i.getInteger());
} else {
vector<NestedInteger> list = i.getList();
for(NestedInteger j : list){
configNums(j, nums);
}
}
}
示例10: putNestedListIntoVector
void putNestedListIntoVector(const NestedInteger &nested) {
if (nested.isInteger()) {
integerList.push_back(nested.getInteger());
} else {
const vector<NestedInteger> &v = nested.getList();
for (int i = 0; i < v.size(); i++) {
putNestedListIntoVector(v[i]);
}
}
}
示例11: dfs
int dfs(NestedInteger& root, int depth) {
if (root.isInteger()) {
return root.getInteger() * depth;
}
int sum = 0;
for (auto child : root.getList()) {
sum += dfs(child, depth - 1);
}
return sum;
}
示例12: dfs
void dfs(NestedInteger& it, vector<int>&result, int dep){
if(result.size() < dep+1){
result.resize(dep+1);
}
if(it.isInteger()){
result[dep] += it.getInteger();
}else{
for(auto t : it.getList()){
dfs(t, result, dep+1);
}
}
}
示例13: getDepth
int getDepth(NestedInteger& root) {
if (root.isInteger()) {
return 1;
}
int depth = 0;
for (auto child : root.getList()) {
depth = max(depth, getDepth(child) + 1);
}
return depth;
}
示例14: helper
int helper(NestedInteger& nestedInteger, int depth) {
if (nestedInteger.isInteger()) {
return nestedInteger.getInteger() * depth;
}
else {
vector<NestedInteger> nestedList = nestedInteger.getList();
int sum = 0;
for (int i = 0; i < nestedList.size(); i++) {
sum += helper(nestedList[i], depth + 1);
}
return sum;
}
}
示例15: hasNext
bool hasNext() {
while(dq.size() && !dq.front().isInteger()){
NestedInteger front = dq.front();
dq.pop_front();
vector<NestedInteger> nls = front.getList();
for(int i = nls.size() - 1; i >= 0; i--){
dq.push_front(nls[i]);
}
}
if(dq.size() && dq.front().isInteger()) return true;
return false;
}