일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- leetcode풀기
- 파이썬 알고리즘
- 파이썬 프로그래머스
- LeetCode
- python zip_longest
- 파이썬알고리즘
- leetcode 풀기
- 파이썬알고리즘풀기
- 잇츠디모
- 알고리즘풀기
- python priority queue
- leetcode풀이
- python 알고리즘
- 릿코드풀기
- 상가수익률계산기
- 파이썬릿코드풀기
- 파이썬 알고리즘 풀기
- binary search
- 릿코드풀이
- python xor
- 릿코드 파이썬
- python sorted
- 파이썬 릿코드
- python 릿코드
- 릿코드
- python Leetcode
- 알고리즘풀이
- 파이썬릿코드
- 코틀린기초
- 릿코드 풀기
- Today
- Total
목록릿코드풀기 (16)
소프트웨어에 대한 모든 것
70. Climbing Stairs https://leetcode.com/problems/climbing-stairs/ Climbing Stairs - 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 문제) 솔루션1) 동적 계획법 풀이 class Solution: def climbStairs(self, n: int) -> int: ''' f(0) = 0 f(1) = 1 f(2) = 2 f(3) = f(2) + f(1) ... f(n) = f(n-1) + (n-2)..
1859. Sorting the Sentence https://leetcode.com/problems/sorting-the-sentence/ Sorting the Sentence - 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 문제) 솔루션1) 1. sentence을 space로 split 2. 단어의 수를 세고, 단어 수 사이즈 만큼 array 생성 3. 각 단어를 반복문을 돌면서 단어의 마지막을 indexing해서 word position 획득 4. arr..
380. Insert Delete GetRandom O(1) https://leetcode.com/problems/insert-delete-getrandom-o1/ Insert Delete GetRandom O(1) - 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 문제) 솔루션1) hash 자료구조 사용 getRandom()은 random.choice() 사용 class RandomizedSet: def __init__(self): ''' Initializes..
1832. Check if the Sentence Is Pangram https://leetcode.com/problems/check-if-the-sentence-is-pangram/ 문제) 솔루션1) 각 알파벳을 해쉬에 저장 sentence에서 문자를 해쉬에서 key 값 서치해서 있으면 삭제 해쉬의 사이즈가 0이면 pangram을 만족하기 때문에 True를 리턴, 아니면 False class Solution: def checkIfPangram(self, sentence: str) -> bool: alphabets = 'abcdefghijklmnopqrstuvwxyz' d = {} for c in alphabets: d[c] = None for c in sentence: if c in d: del d[c..
https://leetcode.com/problems/power-of-two/ Power of Two - 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 문제) 솔루션1) 2의 승수는 A & (A-1) = 0을 만족 예시) 16 -> 10000, 16-1 -> 01111, 16 & 15 -> 10000 & 01111 = 0 class Solution: def isPowerOfTwo(self, n: int) -> bool: if n == 0: return False..
https://leetcode.com/problems/single-number/ Single 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 문제) 풀이 전략) XOR 교환법칙 결합법칙 이용 A^A = 0 A^0=A A^A^B^B^C=0^0^A=A 솔루션1) class Solution: def singleNumber(self, nums: List[int]) -> int: # 모든 값을 xor 취하면 하나만 남음 ret = 0 for num in n..
771. Jewels and Stones 문제) You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels. Letters are case sensitive, so "a" is considered a different type of stone from "A". 솔루션1) class Solution: def numJewelsInStones..
461. Hamming Distance 문제) 솔루션1) xor 연산을 취한 후 비트연산 class Solution: def hammingDistance(self, x: int, y: int) -> int: xor = x ^ y return sum((xor>>i & 1) for i in range(31)) 솔루션2) xor 연산을 취한 후 내장함수 bin()을 사용해서 이진수 문자열로 변환 후 1을 셈 class Solution: def hammingDistance(self, x: int, y: int) -> int: xor = x^y return bin(xor).count('1')