[C++][Java] Clean Code
C++\n\nclass Solution {\npublic:\n    /**\n     * 0            k           2k          3k\n     * |-----------|-----------|-----------|---\n     * +--reverse--+
**C++**\n```\nclass Solution {\npublic:\n    /**\n     * 0            k           2k          3k\n     * |-----------|-----------|-----------|---\n     * +--reverse--+           +--reverse--+\n     */\n    string reverseStr(string s, int k) {\n        for (int left = 0; left < s.size(); left += 2 * k) {\n            for (int i = left, j = min(left + k - 1, (int)s.size() - 1); i < j; i++, j--) {\n                swap(s[i], s[j]);\n            }\n        }\n        return s;\n    }\n};\n```\n\n**Java**\n```\npublic class Solution {\n    public String reverseStr(String s, int k) {\n        char[] ca = s.toCharArray();\n        for (int left = 0; left < ca.length; left += 2 * k) {\n            for (int i = left, j = Math.min(left + k - 1, ca.length - 1); i < j; i++, j--) {\n                char tmp = ca[i];\n                ca[i] = ca[j];\n                ca[j] = tmp;\n            }\n        }\n        return new String(ca);\n    }\n}\n```
[]