题解 | #快速生长的草#
快速生长的草
https://www.nowcoder.com/practice/de1d9ec0d53d4202ae83dc3b25a63166
题目考察的知识点:位运算
题目解答方法的文字分析:个位数不为0或者5,乘2后末尾一定没有0,这个条件就可以防止数据太大造成越界
本题解析所用的编程语言:c++
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param m int整型 * @return int整型 */ int trailingZeroes(int n, int m) { // write code here int count = 0; while (m--) { n *= 2; if (n % 10 == 0) { ++count; n /= 10; } if (n % 10 != 5 && n % 10 != 0) break; } return count; } };