解题思路
思路比较简单,直接遍历像素值即可。时间复杂度为O(mn)
代码
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
vector<int> zhiFangTu1(int n,int m,int L,vector<vector<int>> graph) {
vector<int> res(L,0);
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
res[graph[i][j]]++;
}
}
return res;
}
};
int main() {
int n,m,L;
cin>>n>>m>>L;
vector<vector<int>> graph(n);
for (int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
int temp;
cin>>temp;
graph[i].push_back(temp);
}
}
// cout<<"开始输出:"<<endl;
// cout<<n<<" "<<m<<" "<<L<<endl;
//
// for (auto &single:graph){
// for (auto &num:single){
// cout<<num<<" ";
// }
// cout<<endl;
// }
Solution solution;
vector<int> res=solution.zhiFangTu1(n,m,L,graph);
// cout<<"结果为"<<endl;
for(auto &num:res) {
cout<<num<<" ";
}
}