Skip to content

Commit 3f23510

Browse files
committed
add 1347
1 parent 8ae303a commit 3f23510

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.exe
22
*.out
3-
test.cpp
3+
test.cpp
4+
test.js
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @param {string} s
3+
* @param {string} t
4+
* @return {number}
5+
*/
6+
var minSteps = function(s, t) {
7+
const ms = {};
8+
for (let i=0; i<s.length; i++) {
9+
if (!ms[s[i]]) {
10+
ms[s[i]] = 0;
11+
}
12+
ms[s[i]]++;
13+
}
14+
15+
let diff = 0;
16+
for (let i=0; i<t.length; i++) {
17+
if (!ms[t[i]]) {
18+
ms[t[i]] = 0;
19+
}
20+
if (ms[t[i]] > 0) {
21+
ms[t[i]]--;
22+
} else {
23+
diff++;
24+
}
25+
}
26+
return diff;
27+
};
28+
29+
console.log(minSteps("bab", "aba"));

0 commit comments

Comments
 (0)