# 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://liuxue2010.gitbook.io/data-structure-and-algorithms/array-and-numbers/sort-letters-by-case.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
