Skip to content

Commit c22117d

Browse files
authored
Update js codes.docx
1 parent cbbf415 commit c22117d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

js codes.docx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,20 @@ stringCompression(''); //Please enter valid string.
15281528
stringCompression('aaaa'); //a4
15291529
stringCompression('aaaabbc'); //a4b2c1
15301530
stringCompression('aaaabbcaabb'); //a4b2c1a2b2
1531+
---------------------------------------------------------------
1532+
function stringCompression (str) {
1533+
var output = '';
1534+
var count = 0;
1535+
for (var i = 0; i < str.length; i++){
1536+
count++;
1537+
if (str[i] != str[i+1]) {
1538+
output += str[i] + count;
1539+
count = 0;
1540+
}
1541+
}
1542+
console.log(output);
1543+
}
1544+
stringCompression('aaaab');
15311545
================================================================================================================================================================================
15321546
Code 102: Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.
15331547
A subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be considered as a subtree of itself.

0 commit comments

Comments
 (0)