Algorithm
-
[leetcode 75-19] Number of islandsAlgorithm 2023. 1. 31. 23:22
https://leetcode.com/problems/number-of-islands Number of Islands - LeetCode Number of Islands - Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may ass leetcode.com class Solution(object): def numIslands(self, grid):..
-
[leetcode 75-18] Top K Frequent ElementsAlgorithm 2023. 1. 31. 00:11
https://leetcode.com/problems/top-k-frequent-elements Top K Frequent Elements - LeetCode Top K Frequent Elements - Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: leetcode.com from collections import Counter class Solut..
-
[leetcode 75-17] Coin changeAlgorithm 2023. 1. 30. 23:32
https://leetcode.com/problems/coin-change/ Coin Change - LeetCode Coin Change - You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make up that amount. If that amount of money can leetcode.com class Solution: def coinChange(self, coins: List[int], amount:..
-
[leetcode 75-16] Climbing StairsAlgorithm 2023. 1. 30. 23:08
https://leetcode.com/problems/climbing-stairs/ class Solution: def climbStairs(self, n: int) -> int: if n == 0: return 0 if n == 1: return 1 if n == 2: return 2 dp = [0] * (n+1) dp[1] = 1 dp[2] = 2 for i in range(3,n+1): dp[i] = dp[i-1] + dp[i-2] return dp[n]
-
[leetcode 75-15] Reverse BitsAlgorithm 2023. 1. 30. 22:59
https://leetcode.com/problems/reverse-bits/ Reverse Bits - LeetCode Reverse Bits - Reverse bits of a given 32 bits unsigned integer. Note: * Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your i leetcode.com class Solution: def reverseBits(self, n: int) -> int: return..
-
[leetcode 75-14] Missing NumberAlgorithm 2023. 1. 30. 22:56
https://leetcode.com/problems/missing-number/ Missing Number - LeetCode Missing Number - Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Example 1: Input: nums = [3,0,1] Output: 2 Explanation: n = 3 since there are 3 numbers, so all n leetcode.com class Solution: def missingNumber(self, nums: List[int]) ->..
-
[leetcode 75-12] Number of 1 BitsAlgorithm 2023. 1. 30. 22:34
https://leetcode.com/problems/number-of-1-bits/ Number of 1 Bits - LeetCode Number of 1 Bits - Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight [http://en.wikipedia.org/wiki/Hamming_weight]). Note: * Note that in some languages, such as Java, there is no un leetcode.com class Solution(object): def hammingWeight(self, n): ..