XOR Strings 2

Sort by

recency

|

221 Discussions

|

  • + 0 comments

    Java 7

    public static String stringsXOR(String s, String t) {
            StringBuffer res = new StringBuffer();
            for(int i = 0; i < s.length(); i++) {
                if(s.charAt(i) == t.charAt(i))
                    res.append("0");
                else
                    res.append("1");
            }
    
            return res.toString().trim();
        }
    
  • + 0 comments

    Solution for python:

    def strings_xor(s, t):
        res = ""
        for i in range(len(s)):
            if s[i] == t[i]:
                res += '0';
            else:
                res += '1';
    
        return res
    
    s = input()
    t = input()
    print(strings_xor(s, t))
    
  • + 0 comments

    Solution for python:

    def strings_xor(s, t): res = "" for i in range(len(s)): if s[i] == t[i]: res += '0'; else: res += '1';

    return res
    
  • + 0 comments

    This problem does not work for C++. The test sample will fail, even though the output for your answer and correct answer are the same.

    It will work correctly if you switch the language to Python3. It's the same edits as C++

  • + 0 comments

    This problem worked for me in Python3. The idea is there and you are not going insane, problem does not compile correctly for most options.