LeetCode - Problems - Algorithms - 1365. How Many Numbers Are Smaller Than the Current Number
Problem Description
Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it.
That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i] .
Return the answer in an array.
Example:
Constraints:
My Solution (Python)
class Solution(object):
def smallerNumbersThanCurrent(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
answer = []
for i in range(len(nums)):
counter = 0
for j in range(len(nums)):
if i == j:
continue
else:
if nums[i] > nums[j]:
counter += 1
answer.append(counter)
return answer
'Problem solving > Algorithms' 카테고리의 다른 글
[LeetCode] 1512. Number of Good Pairs (Python) (0) | 2021.01.10 |
---|---|
[LeetCode] 1470. Shuffle the Array (Python) (0) | 2021.01.10 |
[LeetCode] 1108. Defanging an IP Address (Python) (0) | 2021.01.10 |
[LeetCode] 1431. Kids With the Greatest Number of Candies (Python) (0) | 2021.01.09 |
[LeetCode] 1672. Richest Customer Wealth (Python) (0) | 2021.01.09 |