当前位置:首页|资讯

GFG 94 Occurrences of 101

作者:您是打尖儿还是住店呢发布时间:2024-09-24

Geekina gifted Geek a number 'n', and since Geek is away, he asked you to count the number of

times the sequence "101" occurs as a subsequence in the binary representation of 'n'.


Example 1:


Input: 

n = 5


Output:

1


Explanation:

5 in binary is 101, hence "101" only occurring once as the subsequence.


Example 2:


Input: 

n = 21


Output:

4


Explanation:

21 in binary is 10101. "101" is occurring as a subsequence in 4 ways viz. - 

10101

10101

10101

10101


Your Task:  

You don't need to read input or print anything. Your task is to complete the

function count101() which takes an 64-bit integer n as the input and returns the count of number

----

找101子序列的数量,当遇到1的时候,计算前面子字符串的10出现的次数,然后累加即可。

计算10出现的次数,单独写一个函数即可。



Copyright © 2024 aigcdaily.cn  北京智识时代科技有限公司  版权所有  京ICP备2023006237号-1