原来这是昨天的每日一题
This commit is contained in:
parent
e534a5f996
commit
6060329fed
|
@ -1,5 +1,7 @@
|
||||||
package com.cool.one_question_per_day;
|
package com.cool.one_question_per_day;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
*
|
*
|
||||||
|
@ -10,7 +12,22 @@ package com.cool.one_question_per_day;
|
||||||
public class LeetCode20240825 {
|
public class LeetCode20240825 {
|
||||||
|
|
||||||
public int findPermutationDifference(String s, String t) {
|
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","");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue