feat: 2025-10-23打卡

This commit is contained in:
wu xiangkai
2025-10-23 16:32:13 +08:00
parent 59f245dda7
commit f06095ad7e
9 changed files with 378 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
/*
* @lc app=leetcode id=567 lang=java
*
* [567] Permutation in String
*/
// @lc code=start
class Solution {
public boolean checkInclusion(String s1, String s2) {
if(s1.length() > s2.length()) {
return false;
}
int[] c1 = strCompose(s1);
int[] c2 = strCompose(s2.substring(0, s1.length()));
boolean f = isComposeSame(c1, c2);
int j = s1.length();
while(!f && j < s2.length()) {
c2[s2.charAt(j - s1.length())-'a']--;
c2[s2.charAt(j)-'a']++;
if(isComposeSame(c1, c2)) {
f = true;
break;
}
j++;
}
return f;
}
private int[] strCompose(String s) {
int[] c = new int[26];
for(int i = 0; i < s.length(); i++) {
c[s.charAt(i)-'a']++;
}
return c;
}
private boolean isComposeSame(int[] a, int[] b) {
if(a.length != b.length) {
return false;
}
boolean matches = true;
for(int i=0; i<a.length; i++) {
if(a[i] != b[i]) {
matches = false;
break;
}
}
return matches;
}
}
// @lc code=end