调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
中等
相关标签
相关企业
提示

给你两个下标从 0 开始的 二元 字符串 starget ,两个字符串的长度均为 n 。你可以对 s 执行下述操作 任意 次:

  • 选择两个 不同 的下标 ij ,其中 0 <= i, j < n
  • 同时,将 s[i] 替换为 (s[i] OR s[j]) ,s[j] 替换为 (s[i] XOR s[j]) 。

例如,如果 s = "0110" ,你可以选择 i = 0j = 2,然后同时将 s[0] 替换为 (s[0] OR s[2] = 0 OR 1 = 1),并将 s[2] 替换为 (s[0] XOR s[2] = 0 XOR 1 = 1),最终得到 s = "1110"

如果可以使 s 等于 target ,返回 true ,否则,返回 false

 

示例 1:

输入:s = "1010", target = "0110"
输出:true
解释:可以执行下述操作:
- 选择 i = 2 和 j = 0 ,得到 s = "0010".
- 选择 i = 2 和 j = 1 ,得到 s = "0110".
可以使 s 等于 target ,返回 true 。

示例 2:

输入:s = "11", target = "00"
输出:false
解释:执行任意次操作都无法使 s 等于 target 。

 

提示:

  • n == s.length == target.length
  • 2 <= n <= 105
  • starget 仅由数字 01 组成
通过次数
6.2K
提交次数
13.5K
通过率
45.8%

相关标签

相关企业

提示 1
Think of when it is impossible to convert the string to the target.

提示 2
If exactly one of the strings is having all 0’s, then it is impossible. And it is possible in all other cases. Why is that true?


评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
运行和提交代码需要登录
s =
"1010"
target =
"0110"
Source