About copying the code on Leetcode directly into your own environment

Example code (regardless of the pros and cons of the code):
insert image description here
Note: I use an online platform compiler

Problem1

  • NameError:name ‘List’ is not defined
    insert image description here
  • Solution: Add the following code:
from typing import List

Problem2

  • TypeError: threeSumClosest() missing 1 required positional argument: ‘target’
    insert image description here
  • Solution:
S = Solution()
  • Analysis: In Python, the class should be instantiated first, and then the class should be applied. Note that the instantiation process should be parenthesized.

Guess you like

Origin blog.csdn.net/qq_41714549/article/details/131649709