Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d794928

Browse files
committed
Add solution #1433
1 parent a758b3c commit d794928

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,300 LeetCode solutions in JavaScript
1+
# 1,301 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1093,6 +1093,7 @@
10931093
1425|[Constrained Subsequence Sum](./solutions/1425-constrained-subsequence-sum.js)|Hard|
10941094
1431|[Kids With the Greatest Number of Candies](./solutions/1431-kids-with-the-greatest-number-of-candies.js)|Easy|
10951095
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|
10961097
1436|[Destination City](./solutions/1436-destination-city.js)|Easy|
10971098
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|
10981099
1443|[Minimum Time to Collect All Apples in a Tree](./solutions/1443-minimum-time-to-collect-all-apples-in-a-tree.js)|Medium|
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
};

0 commit comments

Comments
 (0)