Skip to content

Commit 8bf31e3

Browse files
committed
Add solution #1347
1 parent 54e99f8 commit 8bf31e3

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,246 LeetCode solutions in JavaScript
1+
# 1,247 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1023,6 +1023,7 @@
10231023
1344|[Angle Between Hands of a Clock](./solutions/1344-angle-between-hands-of-a-clock.js)|Medium|
10241024
1345|[Jump Game IV](./solutions/1345-jump-game-iv.js)|Hard|
10251025
1346|[Check If N and Its Double Exist](./solutions/1346-check-if-n-and-its-double-exist.js)|Easy|
1026+
1347|[Minimum Number of Steps to Make Two Strings Anagram](./solutions/1347-minimum-number-of-steps-to-make-two-strings-anagram.js)|Medium|
10261027
1351|[Count Negative Numbers in a Sorted Matrix](./solutions/1351-count-negative-numbers-in-a-sorted-matrix.js)|Easy|
10271028
1352|[Product of the Last K Numbers](./solutions/1352-product-of-the-last-k-numbers.js)|Medium|
10281029
1356|[Sort Integers by The Number of 1 Bits](./solutions/1356-sort-integers-by-the-number-of-1-bits.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* 1347. Minimum Number of Steps to Make Two Strings Anagram
3+
* https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram/
4+
* Difficulty: Medium
5+
*
6+
* You are given two strings of the same length s and t. In one step you can choose any character
7+
* of t and replace it with another character.
8+
*
9+
* Return the minimum number of steps to make t an anagram of s.
10+
*
11+
* An Anagram of a string is a string that contains the same characters with a different (or the
12+
* same) ordering.
13+
*/
14+
15+
/**
16+
* @param {string} s
17+
* @param {string} t
18+
* @return {number}
19+
*/
20+
var minSteps = function(s, t) {
21+
const charCount = new Array(26).fill(0);
22+
let result = 0;
23+
24+
for (let i = 0; i < s.length; i++) {
25+
charCount[s.charCodeAt(i) - 97]++;
26+
charCount[t.charCodeAt(i) - 97]--;
27+
}
28+
29+
for (const count of charCount) {
30+
if (count > 0) result += count;
31+
}
32+
33+
return result;
34+
};

0 commit comments

Comments
 (0)