File tree 2 files changed +36
-1
lines changed
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,246 LeetCode solutions in JavaScript
1
+ # 1,247 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1023
1023
1344|[ Angle Between Hands of a Clock] ( ./solutions/1344-angle-between-hands-of-a-clock.js ) |Medium|
1024
1024
1345|[ Jump Game IV] ( ./solutions/1345-jump-game-iv.js ) |Hard|
1025
1025
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|
1026
1027
1351|[ Count Negative Numbers in a Sorted Matrix] ( ./solutions/1351-count-negative-numbers-in-a-sorted-matrix.js ) |Easy|
1027
1028
1352|[ Product of the Last K Numbers] ( ./solutions/1352-product-of-the-last-k-numbers.js ) |Medium|
1028
1029
1356|[ Sort Integers by The Number of 1 Bits] ( ./solutions/1356-sort-integers-by-the-number-of-1-bits.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments