Simple & best C++ solution


#1

int countSub(vector a, int b){
int n = a.size();
int count = 0;
for(int i=0; i<n; i++){
int sum = 0;
for(int j=i; j<n; j++){
sum += a[j];
if(sum<=b)
count++;
else
break;
}
}
return count;
}

int Solution::numRange(vector &a, int b, int c) {

return countSub(a, c)-countSub(a, b-1);

}