shuzijun / leetcode-editor

Do Leetcode exercises in IDE, support leetcode.com and leetcode-cn.com, to meet the basic needs of doing exercises.Support theoretically: IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion GoLand DataGrip Rider MPS Android Studio
https://plugins.jetbrains.com/plugin/12132-leetcode-editor
Apache License 2.0
3.71k stars 400 forks source link

Python代码不支持typing #554

Closed yileitu closed 2 years ago

yileitu commented 2 years ago

例如定义一个函数:

def maxChunksToSorted(self, arr: List[int]) -> int:
  pass

LeetCode Console报错:

Compile Error:
    SyntaxError: invalid syntax
                                   ^
    def maxChunksToSorted(self, arr: List[int]) -> int:

去除typing后

def maxChunksToSorted(self, arr):
  pass

可以成功提交。

但是网页版的LeetCode是支持Python typing的。将第一段代码手动复制到网页的编辑器中不会报SyntaxError。望添加对Python typing的支持。

shuzijun commented 2 years ago

题目编号和完整的代码提供一下

yileitu commented 2 years ago

768. Max Chunks To Make Sorted II

class Solution(object):
    def maxChunksToSorted(self, arr: [int]) -> int:
        """
        :type arr: List[int]
        :rtype: int
        """
        mono_stack: List[int] = []

        for num in arr:
            if mono_stack and num < mono_stack[-1]:
                max_in_chunk = mono_stack.pop()
                while mono_stack and num < mono_stack[-1]:
                    mono_stack.pop()
                mono_stack.append(max_in_chunk)
            else:
                mono_stack.append(num)

        return len(mono_stack)
shuzijun commented 2 years ago

需要在配置里,将CodeType改成Python3

yileitu commented 2 years ago

感谢!