如果是'I'就加入当前最小的,是'D'就加入当前最大的.

from collections import Counter, deque


class Solution:
    def diStringMatch(self, S: str) -> List[int]:
        ans = []
        A = deque(range(len(S) + 1))
        for s in S:
            if s=='I':
                ans.append(A.popleft())
            else:
                ans.append(A.pop())
        ans.append(A.pop())

        return ans

 

相关文章:

  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-16
猜你喜欢
  • 2022-12-23
  • 2021-08-16
  • 2021-08-18
  • 2021-07-30
  • 2021-08-08
  • 2022-12-23
相关资源
相似解决方案