File tree 3 files changed +55
-0
lines changed
3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 174
174
| 1047| [ 删除字符串中的所有相邻重复项] ( https://leetcode.cn/problems/remove-all-adjacent-duplicates-in-string/ ) | [ JavaScript] ( ./algorithms/remove-all-adjacent-duplicates-in-string.js ) | Easy|
175
175
| 1780| [ 判断一个数字是否可以表示成三的幂的和] ( https://leetcode.cn/problems/check-if-number-is-a-sum-of-powers-of-three/ ) | [ JavaScript] ( ./algorithms/check-if-number-is-a-sum-of-powers-of-three.js ) | Medium|
176
176
| 1832| [ 判断句子是否为全字母句] ( https://leetcode.cn/problems/check-if-the-sentence-is-pangram/ ) | [ JavaScript] ( ./algorithms/check-if-the-sentence-is-pangram.js ) | Easy|
177
+ | 1945| [ 字符串转化后的各位数字之和] ( https://leetcode.cn/problems/sum-of-digits-of-string-after-convert/ ) | [ JavaScript] ( ./algorithms/sum-of-digits-of-string-after-convert.js ) | Easy|
177
178
| 面试题 04.12| [ 面试题 04.12. 求和路径] ( https://leetcode.cn/problems/paths-with-sum-lcci/ ) | [ JavaScript] ( ./algorithms/paths-with-sum-lcci.js ) | Medium|
178
179
| 面试题 02.07| [ 面试题 02.07. 链表相交] ( https://leetcode.cn/problems/intersection-of-two-linked-lists-lcci/ ) | [ JavaScript] ( ./algorithms/intersection-of-two-linked-lists-lcci.js ) | Easy|
179
180
| 剑指 Offer 05. 替换空格| [ 剑指 Offer 05. 替换空格] ( https://leetcode.cn/problems/ti-huan-kong-ge-lcof/ ) | [ JavaScript] ( ./algorithms/ti-huan-kong-ge-lcof.js ) | Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1945. 字符串转化后的各位数字之和
3
+ * @param {string } s
4
+ * @param {number } k
5
+ * @return {number }
6
+ */
7
+ var getLucky = function ( s , k ) {
8
+ let result = 0 ;
9
+ let sum = '' ;
10
+
11
+ for ( let i = 0 ; i < s . length ; i ++ ) {
12
+ sum += s [ i ] . charCodeAt ( ) - 97 + 1 ;
13
+ }
14
+ while ( k -- ) {
15
+ result = 0 ;
16
+ for ( let i = 0 ; i < sum . length ; i ++ ) {
17
+ result += Number ( sum [ i ] ) ;
18
+ }
19
+ sum = result . toString ( ) ;
20
+ }
21
+
22
+ return result ;
23
+ } ;
Original file line number Diff line number Diff line change
1
+ /*
2
+ * @lc app=leetcode.cn id=1945 lang=javascript
3
+ *
4
+ * [1945] 字符串转化后的各位数字之和
5
+ */
6
+
7
+ // @lc code=start
8
+ /**
9
+ * @param {string } s
10
+ * @param {number } k
11
+ * @return {number }
12
+ */
13
+ var getLucky = function ( s , k ) {
14
+ let result = 0 ;
15
+ let sum = '' ;
16
+
17
+ for ( let i = 0 ; i < s . length ; i ++ ) {
18
+ sum += s [ i ] . charCodeAt ( ) - 97 + 1 ;
19
+ }
20
+ while ( k -- ) {
21
+ result = 0 ;
22
+ for ( let i = 0 ; i < sum . length ; i ++ ) {
23
+ result += Number ( sum [ i ] ) ;
24
+ }
25
+ sum = result . toString ( ) ;
26
+ }
27
+
28
+ return result ;
29
+ } ;
30
+ // @lc code=end
31
+
You can’t perform that action at this time.
0 commit comments