class Solution {
  public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param cowHeights int整型vector
     * @return int整型
     */
    int visibleCows(vector<int>& cowHeights) {
        // write code here
        int n = cowHeights.size();
        int cnt = 1;
        int l = cowHeights[0];
        for (int i = 1; i < n; ++i)
            if (cowHeights[i] > l) {
                ++cnt;
                l = cowHeights[i];
            }
        return cnt;
    }
};

一、题目考察的知识点

简单题

二、题目解答方法的文字分析

直接往后遍历,如果出现了比当前牛高的牛就加一,并且维护一下当前最高牛的高度,就可以了

三、本题解析所用的编程语言

c++