File tree 1 file changed +36
-1
lines changed
1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ https://leetcode-cn.com/problems/factorial-trailing-zeroes/
57
57
58
58
## 代码
59
59
60
- * 语言支持:JS,Python
60
+ * 语言支持:JS,Python,C++, Java
61
61
62
62
Javascript Code:
63
63
@@ -106,6 +106,41 @@ class Solution:
106
106
return n // 5 + self .trailingZeroes(n // 5 )
107
107
```
108
108
109
+ C++ Code:
110
+
111
+ ``` c++
112
+ class Solution {
113
+ public:
114
+ int trailingZeroes(int n) {
115
+ int res = 0;
116
+ while(n >= 5)
117
+ {
118
+ n/=5;
119
+ res += n;
120
+ }
121
+ return res;
122
+ }
123
+ };
124
+ ```
125
+
126
+
127
+ Java Code:
128
+
129
+ ```js
130
+ class Solution {
131
+ public int trailingZeroes(int n) {
132
+ int res = 0;
133
+ while(n >= 5)
134
+ {
135
+ n/=5;
136
+ res += n;
137
+ }
138
+ return res;
139
+ }
140
+ }
141
+ ```
142
+
143
+
109
144
** 复杂度分析**
110
145
- 时间复杂度:$O(logN)$
111
146
- 空间复杂度:$O(1)$
You can’t perform that action at this time.
0 commit comments