말하는대로

  • 홈
  • 태그
  • 방명록

itertools 2

[Leetcode] 1512. Number of Good Pairs

Problem 이번 문제는 배열 안에 같은 값을가지는 ( i,j ) 쌍이 몇가지 있는지 찾는 문제이다 나의 풀이 class Solution: def numIdenticalPairs(self, nums: List[int]) -> int: res = 0 import itertools a_list = itertools.combinations(nums,2) for i in a_list: if i[0] == i[1]: res += 1 return res 이전에 itertools에 있는 combinations를 사용한 기억을 되살려 저걸 활용해서 문제를 풀었다 itertools.combinations(iterable , r) combinations는 iterable 한 객체를 r 의 길이를 가진 조합들을 뽑아내준다..

Python/algorithm 2022.12.25

[Leetcode] 480. Running Sum of 1d Array

Problem - 이 문제는 누적 합을 구하는 문제에용 시원하게 생각나는대로 풀어버린 나의 풀이 class Solution: def runningSum(self, nums: List[int]) -> List[int]: return[sum(nums[:idx+1]) for idx,n in enumerate(nums)] 다른 코드들에 비해 런타임이 길고 메모리사용량이 높아서 너무 궁금해서 다른 풀이 두가지를 찾아보았다 평균적인 런타임 수치의 풀이 class Solution: def runningSum(self, nums: List[int]) -> List[int]: return list(accumulate(nums)) itertools 에 있는 accumulate를 이용하여 값을 뽑았다 ! 누적합을 구해주는 ..

Python/algorithm 2022.12.19
이전
1
다음
더보기
반응형
프로필사진

말하는대로

순간을 후회로 남지않게

  • 분류 전체보기 (78)
    • Python (53)
      • Django (3)
      • algorithm (38)
      • FastAPI (0)
      • core (2)
    • AI (1)
    • Data (3)
    • CS (7)
      • Network (1)
      • 운영체제 (1)
    • Infra (2)
      • GCP (1)
      • CICD (0)
    • etc (3)
    • App (2)
      • Android (1)
      • iOS (1)
      • etc (0)
    • gekco (1)
    • LostArk (0)
    • DesignPattern (1)
    • Project (1)
      • QnA_With_Your_Sentiment (1)
    • Devops (2)

Tag

reptile, OOP, list, 파충류, SQL, 게코, CS, Python, Til, 알고리즘, leetcode, DB, 파이썬, Algorithm, 항해, django, 크레스티드게코, Gecko, class, 백준,

최근글과 인기글

  • 최근글
  • 인기글

최근댓글

공지사항

페이스북 트위터 플러그인

  • Facebook
  • Twitter

Archives

Calendar

«   2025/11   »
일 월 화 수 목 금 토
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

방문자수Total

  • Today :
  • Yesterday :

Copyright © Kakao Corp. All rights reserved.

티스토리툴바