File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 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
22
33[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
44
109310931425|[ Constrained Subsequence Sum] ( ./solutions/1425-constrained-subsequence-sum.js ) |Hard|
109410941431|[ Kids With the Greatest Number of Candies] ( ./solutions/1431-kids-with-the-greatest-number-of-candies.js ) |Easy|
109510951432|[ 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|
109610971436|[ Destination City] ( ./solutions/1436-destination-city.js ) |Easy|
109710981437|[ 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|
109810991443|[ 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