<s>[INST] class Solution {
public:
    string restoreIpAddresses(string s) {
        vector<string> result;
        dfs(s, 0, "", result);
        string finalanswer = "";
        for (string str : result) {
            finalanswer += str + " ";
        }
        return finalanswer.substr(0, finalanswer.size() - 1);
    }
    
    void dfs(string s, int index, string path, vector<string>& result) {
        if (index == s.size() && path.size() >= 7) {
            result.push_back(path.substr(0, path.size() - 3));
            return;
        }
        
        for (int i = 1; i <= 3; i++) {
            if (index + i > s.size())
                break;
            string sub = s.substr(index, i);
            
            if (stoi(sub) <= 255 && (sub[0] != '0' || sub.size() == 1)) {
                dfs(s, index + i, path + sub + ".", result);
            }
        }
    }
};

int main() {
    Solution sol;
    cout << sol.restoreIpAddresses("25525511135");
    return 0;
}

Why does the line `stoi(sub) <= 255` alone not suffice to filter out invalid IP address segments?[/INST]