0
点赞
收藏
分享

微信扫一扫

LintCode题目:合法数统计

萧让听雪 2022-06-29 阅读 39

URL:​​https://www.lintcode.com/problem/legal-number-statistics/description​​

描述

给定​​n​​​个整数和两个正整数​​L​​​,​​R​​​,输出有多少个数的数值范围在​​[L, R]​​之间

  • L≤R

样例

Example 1:

Input: a=[1,2,3,4,5,6],L=3,R=5
Output: 3
Explaination:
Only a[2],a[3],a[4] are in range of [3,5].

Example 2:

Input: a=[1,5,3,3,3,2],L=1,R=2
Output: 2
Explaination:
Only a[0],a[5] are in range of [1,2].

 

代码段中添加:

int count = 0;
for (int i = 0; i < a.size(); i++) {
/* code */
if(a[i]>=L&&a[i]<=R)
count++;
}
return count;

提交结果:
LintCode题目:合法数统计_i++

 


举报

相关推荐

0 条评论