[Java] Clean O(1)-space Solution
\nclass Solution {\n    public int longestBeautifulSubstring(String word) {\n        int res = 0;\n        \n        int len = 1;     // length of current non-d
```\nclass Solution {\n    public int longestBeautifulSubstring(String word) {\n        int res = 0;\n        \n        int len = 1;     // length of current non-decreasing substring\n        int count = 1;   // number of unique char in current non-decreasing substring\n        \n        for (int i = 1; i < word.length(); i++) {\n            char c1 = word.charAt(i);\n            char c2 = word.charAt(i-1);\n            \n            if (c1 < c2) {\n                len = 1;\n                count = 1;\n            } else if (c1 == c2) {\n                len++;\n                if (count == 5) res = Math.max(res, len);\n            } else {\n                len++;\n                count++;\n                if (count == 5) res = Math.max(res, len);\n            }\n        }\n        return res;\n    }\n}\n```
['Java']