魔法师 (@Constanline) 在 Leetcode每日一题 —— 2839. 判断通过操作能否让字符串相等 I 中发帖
思路
只有四位,而且只能同奇偶直接交换,所以只需要比较0与2、1与3即可。
代码
class Solution {
public boolean canBeEqual(String s1, String s2) {
if ((s1.charAt(0) == s2.charAt(0) && s1.charAt(2) == s2.charAt(2))
|| (s1.charAt(0) == s2.charAt(2) && s1.charAt(2) == s2.charAt(0))) {
return (s1.charAt(1) == s2.charAt(1) && s1.charAt(3) == s2.charAt(3))
|| (s1.charAt(1) == s...