HelloMinchan
처음처럼
HelloMinchan
LinkedIn
전체 방문자
오늘
어제
  • 분류 전체보기 (306)
    • Backend (4)
      • NestJS (1)
      • Express (1)
      • Spring (2)
    • Infrastructure (1)
      • AWS (1)
    • Frontend (1)
      • Next.js (1)
    • Language & Runtime (4)
      • Java (2)
      • Node.js (2)
    • Computer Science (8)
      • Computer Networks (3)
      • Operating Systems (4)
      • OOP (1)
    • 독서 (4)
      • 데이터 중심 애플리케이션 설계 (3)
      • 객체지향의 사실과 오해 (1)
    • 회고 (4)
      • Project (2)
      • Career (2)
    • Deprecated (280)

채널

  • GitHub
  • LinkedIn

최근 글

태그

  • 알고스팟
  • 백준Python
  • 프로그래머스Python
  • 프로그래머스
  • 백준Go
  • 프로그래머스C++
  • 개발자
  • Database
  • front-end
  • 알고스팟Python
  • programmers
  • 프로그래밍
  • 백준
  • 데이터베이스
  • Algospot
  • 백엔드
  • back-end
  • 코딩
  • 백준C++
  • Baekjoon Online Judge

최근 댓글

인기 글

hELLO
HelloMinchan

처음처럼

[LeetCode] 리트코드 1365번 How Many Numbers Are Smaller Than the Current Number(Python)
Deprecated

[LeetCode] 리트코드 1365번 How Many Numbers Are Smaller Than the Current Number(Python)

2020. 3. 4. 01:16

Copyright © 2020 LeetCode

[LeetCode] 리트코드 1365번 How Many Numbers Are Smaller Than the Current Number

(Python)

(글쓴날 : 2020.03.04)

 


* LeetCode, 리트코드 1365번 문제 Python 언어 풀이입니다.

* 소스 코드의 저작권은 글쓴이에게 있습니다.


 

 

리트코드 1365번 How Many Numbers Are Smaller Than the Current Number


1) 문제

문제 링크 : https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/

 

How Many Numbers Are Smaller Than the Current Number - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com


2) 풀이 과정

여러 개의 숫자들이 배열(Python의 경우 리스트)로 입력되며, 입력받은 배열(리스트)에 속한 각각의 숫자들을 기준으로 작은 숫자들의 개수를 차례대로 배열(리스트)로 만들어 반환하는 문제입니다.

 

저의 경우, Python으로 해시 테이블을 만들어 문제를 풀었는데 먼저 각 입력받은 배열(리스트)에서 가장 큰  숫자 길이만큼의 해시 테이블을 생성하여 인덱스를 기준으로 인덱스에 해당하는 숫자가 몇 개가 있나 저장하였습니다.

 

그 후, 문제에서 요구하는 입력받은 배열(리스트)의 각 원소보다 작은 숫자의 개수를 구하기 위해 처음의 입력받은 배열(리스트)를 반복하여, 만들어 놓은 해시 테이블에서 해당 원소의 인덱스 앞까지 슬라이싱한 합을 구해 차례대로 배열(리스트)화하여 문제를 해결하였습니다.


3) 코드

 

* Python 코드

1
2
3
4
5
6
7
8
9
class Solution:
 
    def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:
        li = [0] * (max(nums) + 1)
        for i in nums:
            li[i] = (nums.count(i))
        res = [sum(li[:x]) for x in nums]
        
        return res

 

저작자표시 비영리 변경금지 (새창열림)

'Deprecated' 카테고리의 다른 글

[MySQL] 테이블(Table) 생성, 조회, 삭제하는 법  (0) 2020.03.07
[MySQL] 데이터베이스(스키마) 생성, 조회, 사용, 삭제하는 법  (0) 2020.03.06
[LeetCode] 리트코드 1342번 Number of Steps to Reduce a Number to Zero(Python)  (0) 2020.03.03
[CSS] flexbox를 이용한 레이아웃(이미지, div 등) 가운데 정렬하는 법  (0) 2020.03.02
[CSS] 레이아웃 height 100%로 동작하게 하는 법  (2) 2020.03.01
    'Deprecated' 카테고리의 다른 글
    • [MySQL] 테이블(Table) 생성, 조회, 삭제하는 법
    • [MySQL] 데이터베이스(스키마) 생성, 조회, 사용, 삭제하는 법
    • [LeetCode] 리트코드 1342번 Number of Steps to Reduce a Number to Zero(Python)
    • [CSS] flexbox를 이용한 레이아웃(이미지, div 등) 가운데 정렬하는 법
    HelloMinchan
    HelloMinchan
    Though you should not fear failure, You should do your very best to avoid it.

    티스토리툴바