MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / count_bits

Function count_bits

338-counting-bits.rs:17–22  ·  view source on GitHub ↗
(n: i32)

Source from the content-addressed store, hash-verified

15// 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
16
17pub fn count_bits(n: i32) -> Vec<i32> {
18 (0..n+1).map(|i|{
19 let b_vec: Vec<char> = format!("{:b}", i).chars().collect();
20 b_vec.iter().filter(|e|**e=='1').count() as i32
21 }).collect()
22}
23
24fn main() {
25 println!("{:?}", count_bits(5));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected