파이썬 알고리즘 1

김동현·2021년 8월 22일
class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        for i in range(len(nums)):
            for j in range(i+1,len(nums)):
                if nums[i]+ nums[j]==target:
                    return[i,j]

def 선언 부분에

->List[int]:

가 뭔가 했는데
리턴 형식을 명시해준 것이라고 한다

nums: List[int]

c++을 주로 다루다 파이썬을 공부면서
타입에 대한 명시가 없는게 불편한 상황이 있었는데
':'으로 함수선언시에 명시할 수 있는 것으로 보인다

collection
heapq
function
itertools
re
sys
math
bisect
...import

from typing import *

위의 라이브러리들은 별도의 import가 필요하지 않다고 한다

profile
nice to meet you:)

0개의 댓글