统计一个数字在排序数组(从小到大排序)中出现的次数。

// test20.cpp : 定义控制台应用程序的入口点。
//

include "stdafx.h"

include

include

include

include

include

include

include<string.h>

include

using namespace std;

class Solution {
public:
int GetNumberOfK(vector data, int k) {
int count = 0;
for (int i = 0;i < data.size();i++)
{
if(k==data[i])
count++;
}
return count;
}
};
int main()
{

Solution so;
//int count = so.FirstNotRepeatingChar("wangdanwang");
vector data = { 1,2,3,4,5,5,5,6,7,8};
int count = so.GetNumberOfK(data,5);
cout << count << endl;

cout << endl;
return 0;
}

posted @ 2016-11-01 22:09  wdan2016  阅读(266)  评论(0)    收藏  举报