Runtime Error, Leetcode, Longest Substring Without Repeating Characters

This is a leetcode problem, I am getting correct answer for the unlocked test cases but when I submit, I get Runtime error, I don’t think I am able to find out the possible mistake, Please help me to find the mistake, so that I can avoid that in the future.

Problem Link : https://leetcode.com/problems/longest-substring-without-repeating-characters/

class Solution {
public:
int lengthOfLongestSubstring(string s) 
{
    unordered_set<char> us;
    int res = 1;
    for(int i=0;i<s.length()-1;i++)
    {
        int j;
        us.insert(s[i]);
        for( j=i+1;j<s.length();j++)
        {
            if(us.find(s[j])!= us.end())
                break;
            us.insert(s[j]);
        }
        
        res = max(res, j-i);
        us.clear();
    }
    return res;
}
};