[Leetcode]3146. Permutation Difference between Two Strings
2024. 7. 30. 11:52ㆍjava/javaAlgorithm
1. problem :
https://leetcode.com/problems/permutation-difference-between-two-strings/description/
2. solution 1 :
public class Solution {
public int findPermutationDifference(String s, String t) {
int count = 0;
HashMap<Character, Integer> hashMap = new HashMap<>();
for (int i = 0; i < s.length(); i++) {
hashMap.put(s.charAt(i), i);
}
int totalAbsValue = 0;
for (int i = 0; i < t.length(); i++) {
char c = t.charAt(i);
int indexInS = hashMap.get(c);
totalAbsValue += Math.abs(i -indexInS);
}
return totalAbsValue;
}
}
'java > javaAlgorithm' 카테고리의 다른 글
[Leetcode]242. Valid Anagram (0) | 2024.07.30 |
---|---|
[Leetcode]217. Contains Duplicate (0) | 2024.07.30 |
[Leetcode]1679. Max Number of K-Sum Pairs(x) (0) | 2024.07.30 |
[Leetcode]1111. Maximum Nesting Depth of Two Valid(x) (0) | 2024.07.30 |
[Leetcode]11. Container With Most Water (0) | 2024.07.29 |