(n: i32)
| 15 | // 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 |
| 16 | |
| 17 | pub 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 | |
| 24 | fn main() { |
| 25 | println!("{:?}", count_bits(5)); |
nothing calls this directly
no outgoing calls
no test coverage detected