Skip to content

Commit 5af2af7

Browse files
solve #2839: Check if Strings Can be Made Equal With Operations I in java
1 parent 69ac383 commit 5af2af7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@
851851
| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/CountPairsWhoseSumIsLessThanTarget.java) | |
852852
| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/CheckIfAStringIsAnAcronymOfWords.java) | |
853853
| 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | [![Java](assets/java.png)](src/FurthestPointFromOrigin.java) | |
854-
| 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | | |
854+
| 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | [![Java](assets/java.png)](src/CheckIfStringsCanBeMadeEqualWithOperationsI.java) | |
855855
| 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | | |
856856
| 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | | |
857857
| 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array) | | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i
2+
// T: O(N)
3+
// S: O(1)
4+
5+
public class CheckIfStringsCanBeMadeEqualWithOperationsI {
6+
public boolean canBeEqual(String s1, String s2) {
7+
for (int i = 0 ; i < s1.length() - 2 ; i++) {
8+
if (
9+
(s1.charAt(i) == s2.charAt(i) && s1.charAt(i + 2) == s2.charAt(i + 2) ||
10+
(s1.charAt(i) == s2.charAt(i + 2) && s1.charAt(i + 2) == s2.charAt(i)))) {
11+
continue;
12+
}
13+
return false;
14+
}
15+
return true;
16+
}
17+
}

0 commit comments

Comments
 (0)