kyopro_library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub dyktr06/kyopro_library

:warning: lib/others/run_length_encoding.hpp

Code

#pragma once

template <typename T>
vector<pair<T, int>> runLengthEncoding(const vector<T> &a){
    vector<pair<T, int>> res;
    int n = a.size();
    for(int i = 0; i < n; ++i){
        if(res.empty() || res.back().first != a[i]){
            res.emplace_back(a[i], 1);
        } else{
            res.back().second++;
        }
    }
    return res;
}
#line 2 "lib/others/run_length_encoding.hpp"

template <typename T>
vector<pair<T, int>> runLengthEncoding(const vector<T> &a){
    vector<pair<T, int>> res;
    int n = a.size();
    for(int i = 0; i < n; ++i){
        if(res.empty() || res.back().first != a[i]){
            res.emplace_back(a[i], 1);
        } else{
            res.back().second++;
        }
    }
    return res;
}
Back to top page