且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何用字符串中的两个可能的字符替换一个字符

更新时间:2022-12-11 08:41:27

遇到?"时,将其替换为0"并重复出现,然后将其替换为1"并再次出现.

When you encounter a '?', replace it with a '0' and recur, then replace it with a '1' and recur.

private void permute(String s) { 
    ... 
    if (s.charAt(i) == '?') { 
        permute(<replacing '?' with '0'>);
        permute(<replacing '?' with '1'>); 
    } 
    ...
}