2839. Check if Strings Can be Made Equal With Operations I
/**
* Problem: LeetCode 2839 - Check if Strings Can be Made Equal With Operations I
* Difficulty: Easy
* Language: Java
* Author: CodeByTushu
*/
class Solution {
public boolean canBeEqual(String s1, String s2) {
boolean evenMatch = (s1.charAt(0) == s2.charAt(0) && s1.charAt(2) == s2.charAt(2)) ||
(s1.charAt(0) == s2.charAt(2) && s1.charAt(2) == s2.charAt(0));
boolean oddMatch = (s1.charAt(1) == s2.charAt(1) && s1.charAt(3) == s2.charAt(3)) ||
(s1.charAt(1) == s2.charAt(3) && s1.charAt(3) == s2.charAt(1));
return evenMatch && oddMatch;
}
}
"""
Problem: LeetCode 2839 - Check if Strings Can be Made Equal With Operations I
Difficulty: Easy
Language: Python
Author: CodeByTushu
"""
class Solution:
def canBeEqual(self, s1: str, s2: str) -> bool:
even_match = (
(s1[0] == s2[0] and s1[2] == s2[2]) or
(s1[0] == s2[2] and s1[2] == s2[0])
)
odd_match = (
(s1[1] == s2[1] and s1[3] == s2[3]) or
(s1[1] == s2[3] and s1[3] == s2[1])
)
return even_match and odd_match
/**
* Problem: LeetCode 2839 - Check if Strings Can be Made Equal With Operations I
* Difficulty: Easy
* Language: C++
* Author: CodeByTushu
*/
#include <string>
using namespace std;
class Solution {
public:
bool canBeEqual(string s1, string s2) {
bool evenMatch = (s1[0] == s2[0] && s1[2] == s2[2]) ||
(s1[0] == s2[2] && s1[2] == s2[0]);
bool oddMatch = (s1[1] == s2[1] && s1[3] == s2[3]) ||
(s1[1] == s2[3] && s1[3] == s2[1]);
return evenMatch && oddMatch;
}
};
/**
* Problem: LeetCode 2839 - Check if Strings Can be Made Equal With Operations I
* Difficulty: Easy
* Language: JavaScript
* Author: CodeByTushu
*/
var canBeEqual = function(s1, s2) {
const evenMatch = (s1[0] === s2[0] && s1[2] === s2[2]) ||
(s1[0] === s2[2] && s1[2] === s2[0]);
const oddMatch = (s1[1] === s2[1] && s1[3] === s2[3]) ||
(s1[1] === s2[3] && s1[3] === s2[1]);
return evenMatch && oddMatch;
};