From be2fa725f23d94f8b6c88e13b5e5e63b9e96bbc3 Mon Sep 17 00:00:00 2001 From: Cogobonnia <244cogbonnia@gmail.com> Date: Thu, 24 Oct 2024 14:24:55 +0000 Subject: [PATCH 1/5] feat: added Lesson_13 solution for Chelsea --- .../com/codedifferently/lesson13/Lesson13.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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..3e78072e 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,4 +1,6 @@ package com.codedifferently.lesson13; +import java.util.HashMap; +import java.util.Map; public class Lesson13 { @@ -7,6 +9,17 @@ public class Lesson13 { * https://leetcode.com/problems/permutation-difference-between-two-strings */ public int findPermutationDifference(String s, String t) { - return 0; + Map indexMap = new HashMap<>(); + for (int i = 0; i < s.length(); i++) { + indexMap.put(s.charAt(i), i); + } + + int permutationDifference = 0; + for (int i = 0; i < t.length(); i++) { + char ch = t.charAt(i); + int indexInS = indexMap.get(ch); + permutationDifference += Math.abs(indexInS - i); + } + return permutationDifference; } } From 96f392522744a8781b208de9da36a2e64163ad39 Mon Sep 17 00:00:00 2001 From: Cogobonnia <244cogbonnia@gmail.com> Date: Thu, 24 Oct 2024 14:28:54 +0000 Subject: [PATCH 2/5] fix: added './gradlew :maps_app:spotlessApply' script --- .../src/main/java/com/codedifferently/lesson13/Lesson13.java | 1 + 1 file changed, 1 insertion(+) 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 3e78072e..fbc45487 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,4 +1,5 @@ package com.codedifferently.lesson13; + import java.util.HashMap; import java.util.Map; From d03f604d90f2afb2a7d49b550c5cc32f45c306e6 Mon Sep 17 00:00:00 2001 From: Cogobonnia <244cogbonnia@gmail.com> Date: Thu, 24 Oct 2024 17:05:36 +0000 Subject: [PATCH 3/5] feat: added lesson13.ts extra credit for Chelsea --- .../com/codedifferently/lesson13/Lesson13.java | 1 + lesson_13/maps_ts/package-lock.json | 8 ++++---- lesson_13/maps_ts/package.json | 5 ++--- lesson_13/maps_ts/src/lesson13.ts | 18 +++++++++++++++++- 4 files changed, 24 insertions(+), 8 deletions(-) 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 fbc45487..b33556fb 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 @@ -16,6 +16,7 @@ public int findPermutationDifference(String s, String t) { } int permutationDifference = 0; + for (int i = 0; i < t.length(); i++) { char ch = t.charAt(i); int indexInS = indexMap.get(ch); diff --git a/lesson_13/maps_ts/package-lock.json b/lesson_13/maps_ts/package-lock.json index e4efc3d1..3d282dd7 100644 --- a/lesson_13/maps_ts/package-lock.json +++ b/lesson_13/maps_ts/package-lock.json @@ -14,7 +14,7 @@ "@nestjs/testing": "^10.4.4", "@stylistic/eslint-plugin": "^2.8.0", "@types/eslint__js": "^8.42.3", - "@types/jest": "^29.5.13", + "@types/jest": "^29.5.14", "@types/node": "20.12.7", "copyfiles": "^2.4.1", "eslint": "^9.11.1", @@ -1679,9 +1679,9 @@ } }, "node_modules/@types/jest": { - "version": "29.5.13", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.13.tgz", - "integrity": "sha512-wd+MVEZCHt23V0/L642O5APvspWply/rGY5BcW4SUETo2UzPU3Z26qr8jC2qxpimI2jjx9h7+2cj2FwIr01bXg==", + "version": "29.5.14", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.14.tgz", + "integrity": "sha512-ZN+4sdnLUbo8EVvVc2ao0GFW6oVrQRPn4K2lglySj7APvSrgzxHiNNK99us4WDMi57xxA2yggblIAMNhXOotLQ==", "dev": true, "license": "MIT", "dependencies": { diff --git a/lesson_13/maps_ts/package.json b/lesson_13/maps_ts/package.json index d7012e87..7bc8ac9b 100644 --- a/lesson_13/maps_ts/package.json +++ b/lesson_13/maps_ts/package.json @@ -22,7 +22,7 @@ "@nestjs/testing": "^10.4.4", "@stylistic/eslint-plugin": "^2.8.0", "@types/eslint__js": "^8.42.3", - "@types/jest": "^29.5.13", + "@types/jest": "^29.5.14", "@types/node": "20.12.7", "copyfiles": "^2.4.1", "eslint": "^9.11.1", @@ -34,6 +34,5 @@ "tsc-watch": "^6.2.0", "typescript": "^5.6.2", "typescript-eslint": "^8.7.0" - }, - "dependencies": {} + } } diff --git a/lesson_13/maps_ts/src/lesson13.ts b/lesson_13/maps_ts/src/lesson13.ts index 5207487e..09771647 100644 --- a/lesson_13/maps_ts/src/lesson13.ts +++ b/lesson_13/maps_ts/src/lesson13.ts @@ -3,5 +3,21 @@ * https://leetcode.com/problems/permutation-difference-between-two-strings */ export function findPermutationDifference(s: string, t: string): number { - return 0; + const indexMap = new Map(); + + for (let i = 0; i < s.length; i++) { + indexMap.set(s[i], i); + } + + let permutationDifference = 0; + + for (let i = 0; i < t.length; i++) { + const ch = t[i]; + const indexInS = indexMap.get(ch); + if (indexInS !== undefined) { + permutationDifference += Math.abs(indexInS - i); + } + } + + return permutationDifference; } From 32c82b6f657b661a90133d70b0e4a717d1d8388c Mon Sep 17 00:00:00 2001 From: Cogobonnia <244cogbonnia@gmail.com> Date: Thu, 24 Oct 2024 17:08:27 +0000 Subject: [PATCH 4/5] fix: readded './gradlew :maps_app:spotlessApply' again --- .../src/main/java/com/codedifferently/lesson13/Lesson13.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b33556fb..5847508e 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 @@ -16,7 +16,7 @@ public int findPermutationDifference(String s, String t) { } int permutationDifference = 0; - + for (int i = 0; i < t.length(); i++) { char ch = t.charAt(i); int indexInS = indexMap.get(ch); From 1c2b8daf04fadf9c5d01446d354d410c0da55b73 Mon Sep 17 00:00:00 2001 From: Cogobonnia <244cogbonnia@gmail.com> Date: Fri, 25 Oct 2024 13:17:30 +0000 Subject: [PATCH 5/5] fix: changed json files --- lesson_13/maps_ts/package-lock.json | 8 ++++---- lesson_13/maps_ts/package.json | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lesson_13/maps_ts/package-lock.json b/lesson_13/maps_ts/package-lock.json index 3d282dd7..e4efc3d1 100644 --- a/lesson_13/maps_ts/package-lock.json +++ b/lesson_13/maps_ts/package-lock.json @@ -14,7 +14,7 @@ "@nestjs/testing": "^10.4.4", "@stylistic/eslint-plugin": "^2.8.0", "@types/eslint__js": "^8.42.3", - "@types/jest": "^29.5.14", + "@types/jest": "^29.5.13", "@types/node": "20.12.7", "copyfiles": "^2.4.1", "eslint": "^9.11.1", @@ -1679,9 +1679,9 @@ } }, "node_modules/@types/jest": { - "version": "29.5.14", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.14.tgz", - "integrity": "sha512-ZN+4sdnLUbo8EVvVc2ao0GFW6oVrQRPn4K2lglySj7APvSrgzxHiNNK99us4WDMi57xxA2yggblIAMNhXOotLQ==", + "version": "29.5.13", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.13.tgz", + "integrity": "sha512-wd+MVEZCHt23V0/L642O5APvspWply/rGY5BcW4SUETo2UzPU3Z26qr8jC2qxpimI2jjx9h7+2cj2FwIr01bXg==", "dev": true, "license": "MIT", "dependencies": { diff --git a/lesson_13/maps_ts/package.json b/lesson_13/maps_ts/package.json index 7bc8ac9b..d7012e87 100644 --- a/lesson_13/maps_ts/package.json +++ b/lesson_13/maps_ts/package.json @@ -22,7 +22,7 @@ "@nestjs/testing": "^10.4.4", "@stylistic/eslint-plugin": "^2.8.0", "@types/eslint__js": "^8.42.3", - "@types/jest": "^29.5.14", + "@types/jest": "^29.5.13", "@types/node": "20.12.7", "copyfiles": "^2.4.1", "eslint": "^9.11.1", @@ -34,5 +34,6 @@ "tsc-watch": "^6.2.0", "typescript": "^5.6.2", "typescript-eslint": "^8.7.0" - } + }, + "dependencies": {} }