Skip to content

2546. Apply Bitwise Operations to Make Strings Equal

  • Time: $O(n)$
  • Space: $O(1)$
1
2
3
4
5
6
class Solution {
 public:
  bool makeStringsEqual(string s, string target) {
    return (s.find('1') != string::npos) == (target.find('1') != string::npos);
  }
};
1
2
3
4
5
class Solution {
  public boolean makeStringsEqual(String s, String target) {
    return s.contains("1") == target.contains("1");
  }
}
1
2
3
class Solution:
  def makeStringsEqual(self, s: str, target: str) -> bool:
    return ('1' in s) == ('1' in target)