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..40f0831f 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 charLocation = new HashMap(); + + HashMap map = new HashMap(); + int sum = 0; + for (int i = 0; i < s.length(); i++) { + map.putIfAbsent(s.charAt(i), i); + } + for (char key : map.keySet()) { + int indexInt = t.indexOf(Character.toString(key)); + sum += Math.abs(s.indexOf(key) - indexInt); + } + return sum; } }