Sort Letters by Case
Description
Example
Link
Method
- x
- x
Example
- 1
class Solution { public: /** * @param chars: The letters array you should sort. */ void sortLetters(string &s) { // write your code here if (s.empty()) { return; } int len = s.size(); int start = 0; int end = len - 1; while (start < end) { if (!testLower(s[start])) { swap(s[start], s[end]); --end; } else { ++start; } } return; } // test whether the @param ch is the lower letter bool testLower(const char ch) { if ( ch >= 'a' && ch <= 'z') { return true; } return false; } };
Similar problems
x
Tags
x