Java O(n) simple
\nclass Solution {\n    public String sortString(String s) {\n        int[] alphabet = new int[26];\n        \n        for(char c: s.toCharArray()) {\n         
```\nclass Solution {\n    public String sortString(String s) {\n        int[] alphabet = new int[26];\n        \n        for(char c: s.toCharArray()) {\n            alphabet[c - \'a\']++;\n        }\n        \n        int i = 0;\n        boolean plus = true;\n        int len = s.length();\n        StringBuilder sb = new StringBuilder();\n        \n        while(len > 0) {\n            if (alphabet[i] > 0) {\n                sb.append((char) (i + \'a\'));\n                alphabet[i]--;\n                len--;\n            }\n            \n            if (((plus) && (i == 25)) || ((!plus) && (i == 0))) {\n                plus = !plus;\n            } else {\n                i += plus? 1 : -1;\n            }\n        }\n        \n        return sb.toString(); \n    }\n}\n```
['Java']