原来这是昨天的每日一题

This commit is contained in:
Cool 2024-08-25 19:11:50 +08:00
parent e534a5f996
commit 6060329fed
1 changed files with 19 additions and 2 deletions

View File

@ -1,5 +1,7 @@
package com.cool.one_question_per_day;
import org.junit.Test;
/**
* Created with IntelliJ IDEA.
*
@ -10,7 +12,22 @@ package com.cool.one_question_per_day;
public class LeetCode20240825 {
public int findPermutationDifference(String s, String t) {
int[] arr=new int[26];
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++) {
arr[chars[i]-97]=i;
}
int res=0;
char[] chars1 = t.toCharArray();
for (int i = 0; i < chars1.length; i++) {
int index = arr[chars1[i] - 97];
index=Math.abs(index-i);
res+=index;
}
return res;
}
@Test
public void test(){
findPermutationDifference("1","");
}
}