Created
March 21, 2016 22:49
-
-
Save jianminchen/e9667ffa4ff65a6c49b8 to your computer and use it in GitHub Desktop.
Two string - JavaScript - using string to contain 26 characters, then look up each one in two string, use Array.indexOf method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processData(input) { | |
var inputs = input.split("\n"); | |
var numberOfTestCases = inputs[0]; | |
for (var i = 1; i < inputs.length; i += 2) | |
{ | |
var first = inputs[i]; | |
var second = inputs[i + 1]; | |
if (commonSubstring(first, second)) | |
{ | |
console.log("YES"); | |
} | |
else | |
{ | |
console.log("NO"); | |
} | |
} | |
} | |
function commonSubstring(first, second) | |
{ | |
var alphabet = "abcdefghijklmnopqrstuvwxyz"; | |
for (var i = 0; i < 26; i++) | |
{ | |
var character = alphabet[i]; | |
if (first.indexOf(character) > -1 && second.indexOf(character) > -1) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
process.stdin.resume(); | |
process.stdin.setEncoding("ascii"); | |
_input = ""; | |
process.stdin.on("data", function (input) { | |
_input += input; | |
}); | |
process.stdin.on("end", function () { | |
processData(_input); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment