LeetCode Biweekly Contest 19 2問目 - Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold [1343]

Source

LeetCode Biweekly Contest 19
問題文

問題概要

省略

解法

省略

cLayversion 20200214-1)のコード

C++に変換後のコードはこちら

#define main dummy_main
{}
#undef main

class Solution {
public:
  int numOfSubarrays(vector<int>& A, int K, int threshold) {
    int res = 0, N = A.size();
    ll s = 0;
    rep(i,N) A[i] -= threshold;

    rep(i,K) s += A[i];
    if(s >= 0) res++;
    rep(i,K,N){
      s += A[i] - A[i-K];
      if(s >= 0) res++;
    }
    return res;
  }
};

Current time: 2024年03月29日16時39分40秒
Last modified: 2020年02月16日03時20分32秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る

Logged in as: unknown user (not login)

ログイン: