We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 994739c commit 0b29d4eCopy full SHA for 0b29d4e
Algorithms/License Key Formatting/license-key-formatting.js
@@ -0,0 +1,29 @@
1
+// Source : https://leetcode.com/problems/license-key-formatting/
2
+// Author : Han Zichi
3
+// Date : 2017-01-11
4
+// Runtime: 86 ms
5
+
6
+// Your runtime beats 100.00% of javascript submissions
7
8
+/**
9
+ * @param {string} S
10
+ * @param {number} K
11
+ * @return {string}
12
+ */
13
+var licenseKeyFormatting = function(S, K) {
14
+ S = S.toUpperCase().replace(/-/g, '');
15
16
+ let ans = [];
17
+ let index = 0;
18
19
+ if (S.length % K) {
20
+ let str = S.substr(0, S.length % K);
21
+ ans.push(str);
22
+ index = S.length % K;
23
+ }
24
25
+ for (let i = index, len = S.length; i < len; i += K)
26
+ ans.push(S.substr(i, K));
27
28
+ return ans.join('-');
29
+};
0 commit comments