Login Register


How would I even make this faster? filter_list
Author
Message
How would I even make this faster? #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.
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?

Reply





Messages In This Thread
How would I even make this faster? - by ProfessorChill - 07-26-2018, 10:46 PM
RE: How would I even make this faster? - by Blink - 07-27-2018, 04:47 AM
RE: How would I even make this faster? - by Blink - 07-27-2018, 05:16 AM
RE: How would I even make this faster? - by reGEN - 07-27-2018, 06:41 AM



Users browsing this thread: 1 Guest(s)