EASY 0ms solution C++
\n\n# Code\n\nclass Solution {\npublic:\n    string reverseStr(string s, int k) {\n        int n = s.size();\n        for (int i = 0; i < n; i += 2 * k) {\n    
\n\n# Code\n```\nclass Solution {\npublic:\n    string reverseStr(string s, int k) {\n        int n = s.size();\n        for (int i = 0; i < n; i += 2 * k) {\n            if (i + k <= n) {\n                reverse(s.begin() + i, s.begin() + i + k);\n            } else {\n                reverse(s.begin() + i, s.end());\n            }\n        }\n        return s;\n    }\n};\n\n```\n> ***PLEASE UPVOTE IF YOU FOUND THIS HELPFUL.***\n![image.png](https://assets.leetcode.com/users/images/ab328475-ab8c-42cc-b2f1-a7f88b8e5d05_1689079358.8654864.png)\n\n\n
['C++']