File tree 2 files changed +37
-1
lines changed
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,300 LeetCode solutions in JavaScript
1
+ # 1,301 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1093
1093
1425|[ Constrained Subsequence Sum] ( ./solutions/1425-constrained-subsequence-sum.js ) |Hard|
1094
1094
1431|[ Kids With the Greatest Number of Candies] ( ./solutions/1431-kids-with-the-greatest-number-of-candies.js ) |Easy|
1095
1095
1432|[ Max Difference You Can Get From Changing an Integer] ( ./solutions/1432-max-difference-you-can-get-from-changing-an-integer.js ) |Medium|
1096
+ 1433|[ Check If a String Can Break Another String] ( ./solutions/1433-check-if-a-string-can-break-another-string.js ) |Medium|
1096
1097
1436|[ Destination City] ( ./solutions/1436-destination-city.js ) |Easy|
1097
1098
1437|[ Check If All 1's Are at Least Length K Places Away] ( ./solutions/1437-check-if-all-1s-are-at-least-length-k-places-away.js ) |Easy|
1098
1099
1443|[ Minimum Time to Collect All Apples in a Tree] ( ./solutions/1443-minimum-time-to-collect-all-apples-in-a-tree.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1433. Check If a String Can Break Another String
3
+ * https://leetcode.com/problems/check-if-a-string-can-break-another-string/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given two strings: s1 and s2 with the same size, check if some permutation of string s1 can
7
+ * break some permutation of string s2 or vice-versa. In other words s2 can break s1 or vice-versa.
8
+ *
9
+ * A string x can break string y (both of size n) if x[i] >= y[i] (in alphabetical order) for all
10
+ * i between 0 and n-1.
11
+ */
12
+
13
+ /**
14
+ * @param {string } s1
15
+ * @param {string } s2
16
+ * @return {boolean }
17
+ */
18
+ var checkIfCanBreak = function ( s1 , s2 ) {
19
+ const sorted1 = s1 . split ( '' ) . sort ( ) ;
20
+ const sorted2 = s2 . split ( '' ) . sort ( ) ;
21
+
22
+ let canBreak1 = true ;
23
+ let canBreak2 = true ;
24
+
25
+ for ( let i = 0 ; i < s1 . length ; i ++ ) {
26
+ if ( sorted1 [ i ] < sorted2 [ i ] ) {
27
+ canBreak1 = false ;
28
+ }
29
+ if ( sorted2 [ i ] < sorted1 [ i ] ) {
30
+ canBreak2 = false ;
31
+ }
32
+ }
33
+
34
+ return canBreak1 || canBreak2 ;
35
+ } ;
You can’t perform that action at this time.
0 commit comments