File tree 3 files changed +79
-0
lines changed
solution/1900-1999/1945.Sum of Digits of String After Convert
3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,34 @@ impl Solution {
186
186
}
187
187
```
188
188
189
+ ### ** PHP**
190
+
191
+ ``` php
192
+ class Solution {
193
+ /**
194
+ * @param String $s
195
+ * @param Integer $k
196
+ * @return Integer
197
+ */
198
+ function getLucky($s, $k) {
199
+ $rs = "";
200
+ for ($i = 0; $i < strlen($s); $i++) {
201
+ $num = ord($s[$i]) - 96;
202
+ $rs = $rs.strval($num);
203
+ }
204
+ while ($k != 0) {
205
+ $sum = 0;
206
+ for ($j = 0; $j < strlen($rs); $j++) {
207
+ $sum += intval($rs[$j]);
208
+ }
209
+ $rs = strval($sum);
210
+ $k--;
211
+ }
212
+ return intval($rs);
213
+ }
214
+ }
215
+ ```
216
+
189
217
### ** ...**
190
218
191
219
```
Original file line number Diff line number Diff line change @@ -177,6 +177,34 @@ impl Solution {
177
177
}
178
178
```
179
179
180
+ ### ** PHP**
181
+
182
+ ``` php
183
+ class Solution {
184
+ /**
185
+ * @param String $s
186
+ * @param Integer $k
187
+ * @return Integer
188
+ */
189
+ function getLucky($s, $k) {
190
+ $rs = "";
191
+ for ($i = 0; $i < strlen($s); $i++) {
192
+ $num = ord($s[$i]) - 96;
193
+ $rs = $rs.strval($num);
194
+ }
195
+ while ($k != 0) {
196
+ $sum = 0;
197
+ for ($j = 0; $j < strlen($rs); $j++) {
198
+ $sum += intval($rs[$j]);
199
+ }
200
+ $rs = strval($sum);
201
+ $k--;
202
+ }
203
+ return intval($rs);
204
+ }
205
+ }
206
+ ```
207
+
180
208
### ** ...**
181
209
182
210
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * @param String $s
4
+ * @param Integer $k
5
+ * @return Integer
6
+ */
7
+ function getLucky ($s , $k ) {
8
+ $rs = " " ;
9
+ for ($i = 0 ; $i < strlen ($s ); $i ++ ) {
10
+ $num = ord ($s [$i ]) - 96 ;
11
+ $rs = $rs . strval ($num );
12
+ }
13
+ while ($k != 0 ) {
14
+ $sum = 0 ;
15
+ for ($j = 0 ; $j < strlen ($rs ); $j ++ ) {
16
+ $sum += intval ($rs [$j ]);
17
+ }
18
+ $rs = strval ($sum );
19
+ $k -- ;
20
+ }
21
+ return intval ($rs );
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments