Check If a String Can Break Another String LeetCode solution in Java

1
class Solution {
2
public boolean checkIfCanBreak(String s1, String s2) {
3
int n = s1.length();
4
char[] one = s1.toCharArray();
5
char[] two = s2.toCharArray();
6
Arrays.sort(one);
7
Arrays.sort(two);
8
if (check(one, two, n) || check(two, one, n)) {
9
return true;
10
}
11
return false;
12
}
13

14
public boolean check(char[] one, char[] two, int n) {
15
for (int i = 0; i < n; i++) {
16
if (one[i] - 'a' > two[i] - 'a') {
17
return false;
18
}
19
}
20
return true;
21
}
22
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0