LeetCode Weekly Contest 166 2問目 - Group the People Given the Group Size They Belong To [1282]

Source

LeetCode Weekly Contest 166
問題文

問題概要

省略

解法

省略

cLayversion 20191214-1)のコード

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

#define main dummy_main
{}
#undef main

class Solution {
public:
  vector<vector<int>> groupThePeople(vector<int>& g) {
    int i, k, N = g.size();
    vector<int> tmp[501];
    vector<vector<int>> res;
    rep(i,N){
      k = g[i];
      tmp[k].push_back(i);
      if(tmp[k].size() == k){
        res.push_back(tmp[k]);
        tmp[k].clear();
      }
    }
    return res;
  }
};

Current time: 2024年04月25日22時22分47秒
Last modified: 2019年12月14日22時59分02秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る

Logged in as: unknown user (not login)

ログイン: