File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 462
462
1765|[ Map of Highest Peak] ( ./1765-map-of-highest-peak.js ) |Medium|
463
463
1768|[ Merge Strings Alternately] ( ./1768-merge-strings-alternately.js ) |Easy|
464
464
1780|[ Check if Number is a Sum of Powers of Three] ( ./1780-check-if-number-is-a-sum-of-powers-of-three.js ) |Medium|
465
+ 1790|[ Check if One String Swap Can Make Strings Equal] ( ./1790-check-if-one-string-swap-can-make-strings-equal.js ) |Easy|
465
466
1791|[ Find Center of Star Graph] ( ./1791-find-center-of-star-graph.js ) |Easy|
466
467
1812|[ Determine Color of a Chessboard Square] ( ./1812-determine-color-of-a-chessboard-square.js ) |Easy|
467
468
1817|[ Finding the Users Active Minutes] ( ./1817-finding-the-users-active-minutes.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1790. Check if One String Swap Can Make Strings Equal
3
+ * https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are given two strings s1 and s2 of equal length. A string swap is an operation where
7
+ * you choose two indices in a string (not necessarily different) and swap the characters
8
+ * at these indices.
9
+ *
10
+ * Return true if it is possible to make both strings equal by performing at most one string
11
+ * swap on exactly one of the strings. Otherwise, return false.
12
+ */
13
+
14
+ /**
15
+ * @param {string } s1
16
+ * @param {string } s2
17
+ * @return {boolean }
18
+ */
19
+ var areAlmostEqual = function ( s1 , s2 ) {
20
+ const indices = [ ] ;
21
+ for ( const i in s1 ) {
22
+ if ( s1 [ i ] !== s2 [ i ] && indices . push ( i ) > 2 ) return false ;
23
+ }
24
+ return s1 [ indices [ 0 ] ] === s2 [ indices [ 1 ] ] && s1 [ indices [ 1 ] ] === s2 [ indices [ 0 ] ] ;
25
+ } ;
You can’t perform that action at this time.
0 commit comments