LeetCode_Study_Plan/Algorithm
567. Permutation in String java
개발하는루루
2022. 12. 21. 11:08
https://leetcode.com/problems/permutation-in-string/
Permutation in String - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
class Solution {
public boolean checkInclusion(String s1, String s2) {
s1 = sort(s1);
for (int i = 0; i < s2.length()-s1.length()+1; i++) {
if (s1.equals(sort(s2.substring(i, i+s1.length())))) {
return true;
}
}
return false;
}
public String sort(String s) {
char[] s1 = s.toCharArray();
Arrays.sort(s1);
return new String(s1);
}
}