Help with Time Complexity

Problem:

My code:

class Solution {
public:
    vector<int> partitionLabels(string s) {
        map<char,int> m; //last index of each character in s
        vector<int> ans;
        for(int i=0;i<s.length();i++){
            m[s[i]]=i;
        }
        int i=0;
        while(i<s.length()){
            char current=s[i];
            int last_index=m[current];
            int j=i;
            while(j<=last_index){
                last_index=max(last_index,m[s[j]]);
                j++;
            }
            ans.push_back(j-i);
            i=j;
        }
        return ans;
    }
};

Whats the time complexity is it O(n)?

Other than the above loop everything else is trivial.
Here , in the worst case (I think when all characters are unique), this loop runs zero times (j never gets increment) and you have to iterate over all characters.
So, it is O(n).