> For the complete documentation index, see [llms.txt](https://liuxue2010.gitbook.io/data-structure-and-algorithms/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://liuxue2010.gitbook.io/data-structure-and-algorithms/array-and-numbers/sort-letters-by-case.md).

# Sort Letters by Case

Given a string which contains only letters. Sort it by lower case first and upper case second.

## Example

For "abAcD", a reasonable answer is "acbAD"

## Solution

先滑动在交换。

忘记了 <=

while left <= right:

```
class Solution:
    """
    @param chars: The letters array you should sort.
    """
    def sortLetters(self, chars):
        n = len(chars)

        left, right = 0, len(chars) - 1

        while left <= right:
            while left <= right and chars[left] == chars[left].lower():
                left += 1

            while left <= right and chars[right] == chars[right].upper():
                right -= 1

            if left <= right:
                chars[left], chars[right] = chars[right], chars[left]
                left += 1
                right -= 1
```
