simple c++ solution


  • 0
    R
            int a = 0, l = 0;
            for(int i = 0; i < s.size(); i++) {
                a += s[i] == 'A' ? 1 : 0;
                if(s[i] == 'L') l= (i != 0 && s[i-1] == 'L') ? l+1 : 1; 
                if(a > 1 || l > 2) return false;
            }
            return true;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.