Day - 97
Assalomu alaykum, everyone! It is the 97th day! I am glad to see you here! Today I am going to show a solution for strings!
Time Complexity:
The time complexity of the code is O(n^2), where n is the length of the array of strings. This is because the inner loop iterates through each string in the array, and the outer loop iterates through the array of strings. The total number of iterations is n * n, which is O(n^2).
Space Complexity:
The space complexity of the code is O(n), where n is the length of the array of strings. This is because the code creates two arrays, res and tempRes, which both have a length of n.
Code:
/*
?* @param {string[]} words
?* @return {string}
?*/
var oddString = function (words) {
? var res = [];
? for (var i = 0; i < words.length; i++) {
? ? var tempRes = [];
? ? for (var j = 1; j < words[i].length; j++) {
? ? ? tempRes.push(words[i].charCodeAt(j - 1) - words[i].charCodeAt(j));
? ? }
? ? res.push(tempRes);
? }
? for (var i = 0; i < res.length; i++) {
? ? if (res.filter((x) => x.toString() == res[i].toString()).length == 1) {
? ? ? return words[i];
? ? }
? }
};
That's all about today's challenge!
Backend Software Engineer | Scrum Master | Green White Solutions
1 年Very useful