File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 3
3
* https://leetcode.com/problems/permutation-difference-between-two-strings
4
4
*/
5
5
export function findPermutationDifference ( s : string , t : string ) : number {
6
- return 0 ;
7
- }
6
+ let permuDifference = 0 ;
7
+ // Created a counter to track Permutation Difference
8
+ for ( let i = 0 ; i < s . length ; i ++ ) {
9
+ // Loops through each letter in string 's'
10
+ const difference = s . indexOf ( s . charAt ( i ) ) - t . indexOf ( s . charAt ( i ) ) ;
11
+ // Subtracts possitional value of string 't' from the possitional value of string 's'
12
+ permuDifference += Math . abs ( difference ) ;
13
+ // Converts difference into absolute value and adds it to the Permutation Difference
14
+ }
15
+ return permuDifference ;
16
+ // Returns the total Permutation Difference value
17
+ }
18
+
You can’t perform that action at this time.
0 commit comments