标签:
A typical swapping.
class Solution { public: /** * @param chars: The letters array you should sort. */ bool isUpper(char c) { return c >=‘A‘ && c <= ‘Z‘; } void sortLetters(string &letters) { size_t len = letters.length(); if (len < 2) return; int i = 0, j = 0, k = len - 1; while(i <= k) { if (isUpper(letters[j])) { swap(letters[j], letters[k--]); } else { swap(letters[i ++], letters[j]); j = i; } } } };
LintCode "Sort Letters by Case"
标签:
原文地址:http://www.cnblogs.com/tonix/p/4828701.html