Skip to content

Commit 0190cf4

Browse files
add 3146
1 parent 104c885 commit 0190cf4

File tree

2 files changed

+21
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/fourththousand

2 files changed

+21
-0
lines changed

Diff for: paginated_contents/algorithms/4th_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
| 3158 | [Find the XOR of Numbers Which Appear Twice](https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3158.java) | | Easy |
4040
| 3157 | [Find the Level of Tree with Minimum Sum](https://leetcode.com/problems/find-the-level-of-tree-with-minimum-sum/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3157.java) | | Medium |BFS
4141
| 3151 | [Special Array I](https://leetcode.com/problems/special-array-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3151.java) | | Easy |
42+
| 3146 | [Permutation Difference between Two Strings](https://leetcode.com/problems/permutation-difference-between-two-strings/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3146.java) | | Easy |
4243
| 3142 | [Check if Grid Satisfies Conditions](https://leetcode.com/problems/check-if-grid-satisfies-conditions/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3142.java) | | Easy |
4344
| 3131 | [Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3131.java) | | Easy |
4445
| 3127 | [Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3127.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _3146 {
7+
public static class Solution1 {
8+
public int findPermutationDifference(String s, String t) {
9+
Map<Character, Integer> map = new HashMap<>();
10+
for (int i = 0; i < s.length(); i++) {
11+
map.put(s.charAt(i), i);
12+
}
13+
int sum = 0;
14+
for (int i = 0; i < t.length(); i++) {
15+
sum += Math.abs(map.get(t.charAt(i)) - i);
16+
}
17+
return sum;
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)