How would I even make this faster? 07-26-2018, 10:46 PM
#1
I did this challenge, because I like learning by doing challenges.
http://i.imgur.com/SZzrXSp.png
But it can clearly go faster, but I'm not sure how I'd do that.
Any tips?
http://i.imgur.com/SZzrXSp.png
But it can clearly go faster, but I'm not sure how I'd do that.
Code:
class Solution
{
public:
int lengthOfLongestSubstring(std::string s)
{
size_t x;
int y, result;
int index[128];
std::memset(index, 0, sizeof(index));
result = y = 0;
for (x = 0; x < s.length(); x++) {
y = std::max(index[static_cast<int>(s[x])], y);
result = std::max(result, static_cast<int>(x - y + 1));
index[static_cast<int>(s[x])] = x + 1;
}
return result;
}
};Any tips?




![[Image: dEDyx9w.png]](https://i.imgur.com/dEDyx9w.png)
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)