File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13 Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,24 @@ public class Lesson13 {
5
5
/**
6
6
* Provide the solution to LeetCode 3146 here:
7
7
* https://leetcode.com/problems/permutation-difference-between-two-strings
8
+ * You are given two strings s and t such that every character occurs at most once in s and t is a permutation of s.
9
+ * The permutation difference between s and t is defined as
10
+ * the sum of the absolute difference between the index of the occurrence
11
+ * of each character in s and the index of the occurrence of the same character in t.
12
+ * Return the permutation difference between s and t.
8
13
*/
9
14
public int findPermutationDifference (String s , String t ) {
10
- return 0 ;
15
+
16
+ int permuDifference = 0 ;
17
+ // Created a counter to track Permutation Difference
18
+ for (int i = 0 ; i < s .length (); i ++) {
19
+ // Loops through each letter in string 's'
20
+ int difference = s .indexOf (s .charAt (i )) - t .indexOf (s .charAt (i ));
21
+ // Subtracts possitional value of string 't' from the possitional value of string 's'
22
+ permuDifference += Math .abs (difference );
23
+ // Converts difference into absolute value and adds it to the Permutation Difference
24
+ }
25
+ return permuDifference ;
26
+ // Returns the total Permutation Difference value
11
27
}
12
28
}
You can’t perform that action at this time.
0 commit comments