LeetCode 1282 : C++ Solution | Group the People Given the Group Size They Belong To

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 5

  • @stavanmehta4771
    @stavanmehta4771 Год назад +1

    Connect the strings, but not it a literal way.

  • @mrsubham277
    @mrsubham277 Год назад +1

    Lovely❤😊

  • @labanidas4318
    @labanidas4318 Год назад

    class Solution {
    public:
    vector groupThePeople(vector& groupSizes) {
    vector groups;
    unordered_map groupMap;
    // Iterate through the groupSizes vector
    for (int i = 0; i < groupSizes.size(); i++) {
    int size = groupSizes[i];

    // Add the person to the corresponding group based on their group size
    groupMap[size].push_back(i);

    // If the group size is equal to the number of people in the group, add it to the result
    if (groupMap[size].size() == size) {
    groups.push_back(groupMap[size]);
    groupMap[size].clear(); // Clear the group
    }
    }

    return groups;
    }
    };

  • @Harish-rz4gv
    @Harish-rz4gv Год назад +1

    Nice