diff --git a/lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13/Lesson13.java b/lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13/Lesson13.java index 0c981abb..e4873c38 100644 --- a/lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13/Lesson13.java +++ b/lesson_13/maps_java/maps_app/src/main/java/com/codedifferently/lesson13/Lesson13.java @@ -1,5 +1,7 @@ package com.codedifferently.lesson13; +import java.util.HashMap; + public class Lesson13 { /** @@ -7,6 +9,18 @@ public class Lesson13 { * https://leetcode.com/problems/permutation-difference-between-two-strings */ public int findPermutationDifference(String s, String t) { - return 0; + var stringS = new HashMap(); + + int totalDifference = 0; + + for (int sIndex = 0; sIndex < s.length(); sIndex++) { + stringS.put(s.charAt(sIndex), sIndex); + } + for (int tIndex = 0; tIndex < t.length(); tIndex++) { + int countIndexS = stringS.put(t.charAt(tIndex), tIndex); + + totalDifference += Math.abs(countIndexS - tIndex); + } + return totalDifference; } }