일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- type
- property
- Python
- scss
- C++
- vuetify
- Clone
- dotenv
- npm
- C#
- webpack
- vue.js
- security
- AI
- TypeScript
- bash
- var
- generic
- 보안
- machine learning
- VUE
- condition
- nginx
- loop
- 앙상블
- leetcode
- git
- docker
- BOJ
- JavaScript
- Today
- Total
목록PS/LeetCode (49)
ice rabbit programming
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 제목 그대로, 입력된 숫자가 2의 제곱수인지를 판별하는 문제이다. 고전적으로 계속 2로 나누는 방식을 선택했는데, 무리없이 해결되었다. class Solution: def isPowerOfTwo(self, n: int) -> bool: if n 1: if n%2 != 0: re..
leetcode.com/problems/contains-duplicate/ Contains Duplicate - 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 주어진 배열에서, 원소가 두 번 등장하는지를 체크하는 문제이다. 파이썬에서 set은 중복을 허용하지 않는 자료구조임을 이용하여 풀었다. class Solution: def containsDuplicate(self, nums: List[int]) -> bool: return len(nums) != len(s..
leetcode.com/problems/number-of-1-bits/ Number of 1 Bits - 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 hammingWeight(self, n: int) -> int: return str(bin(n)).count('1')
leetcode.com/problems/reverse-bits/ Reverse Bits - 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 32비트로 고정된 길이의 input을 받아 뒤집어 10진수로 변환하는 문제이다. 파이썬의 내장 함수인 bin()를 사용하면, 이진수로 바꿀 수 있다. 예를들어 4는 0b100 으로 변환된다. 앞에 0b가 붙는 것과, 32비트로 고정된 길이지만 앞의 padding용 0은 지워진다는 점을 이용해, 변환 후 앞 2문자를 제거하고 길..
leetcode.com/problems/find-the-difference/ Find the Difference - 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 문자열이 두 개 주어지는데, 임의의 위치에서 하나의 문자가 다르게 들어오는데, 이 문자를 찾는 문제이다. 두 문자를 모두 정렬한 후에 비교해서 다른 index의 문자를 반환하는 식으로 풀었다. class Solution: def findTheDifference(self, s: str, t: str) -..
leetcode.com/problems/find-all-numbers-disappeared-in-an-array/ Find All Numbers Disappeared in an Array - 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 PS를 C++로 풀다가 C#으로 풀고, 이제는 Python으로 풀고 있다. Python이 확실히 내장 함수도 많고 숏코딩에 적합해서 훨씬 편하긴 한 것 같다. 물론 로직 고민은 똑같지만.. 이 문제는 1~배열길이 숫자들이 1번 ..
leetcode.com/problems/move-zeroes/ Move Zeroes - 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 5월 이후로 첫 PS 포스팅이다. 사실상 그 동안 한 달에 한 문제 풀까말까한 수준(...)이었다. 코로나19로 인해 의도치 않게 여유가 생긴 김에 조금 풀어 보았다. 문제는 리스트가 주어지고, 원소 중에 0을 모두 맨 뒷부분으로 빼는 문제이다. 단, 새로운 list를 쓰면 안되고 in-place로 풀어야 한다. 새로운 list를..
https://leetcode.com/problems/single-element-in-a-sorted-array/ Single Element in a Sorted Array - 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 업무에 조금 바쁘다보니 챌린지를 사실상 접었다..하하 ㅠㅠ 정렬된 배열에서 한 번만 등장하는 원소를 찾는 문제였다. 예전에 비슷한 문제를 풀었던 것 같은데 잘 기억나지 않는다. bool, map 등을 사용하는 생각을 했지만 그냥 간단하게 구현..