LeetCode Biweekly Contest 15 3問目 - Iterator for Combination [1286]

Source

LeetCode Biweekly Contest 15
問題文

問題概要

省略

解法

省略

cLayversion 20191214-1)のコード

C++に変換後のコードはこちら

#define main dummy_main
{}
#undef main

int sz, cur, n;
string alpha; int len;
string now;
string res[10100];

void doit(int dep, int st){
  if(sz >= 10010) return;
  if(dep==len) res[sz++] = now, return;
  rep(i,st,n){
    now[dep] = alpha[i];
    doit(dep+1, i+1);
  }
}

class CombinationIterator {
public:
  CombinationIterator(string characters, int combinationLength) {
    sz = cur = 0;
    alpha = characters;
    len = combinationLength;
    n = alpha.size();
    now = "";
    rep(i,len) now += 'a';
    doit(0, 0);
  }
  string next() {
    return res[cur++];
  }
  bool hasNext() {
    return cur < sz;
  }
};

Current time: 2024年04月20日15時23分00秒
Last modified: 2019年12月22日19時46分51秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る

Logged in as: unknown user (not login)

ログイン: