Check If a String Can Break Another String LeetCode solution in Java
1class Solution {2public boolean checkIfCanBreak(String s1, String s2) {3int n = s1.length();4char[] one = s1.toCharArray();5char[] two = s2.toCharArray();6Arrays.sort(one);7Arrays.sort(two);8if (check(one, two, n) || check(two, one, n)) {9return true;10}11return false;12}1314public boolean check(char[] one, char[] two, int n) {15for (int i = 0; i < n; i++) {16if (one[i] - 'a' > two[i] - 'a') {17return false;18}19}20return true;21}22}