일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- SW Expert Academy
- 맥북
- 더현대서울 맛집
- AI 경진대회
- 백준
- Git
- ubuntu
- 프로그래머스
- 우분투
- Baekjoon
- github
- ChatGPT
- 편스토랑
- programmers
- 코로나19
- Real or Not? NLP with Disaster Tweets
- hackerrank
- Docker
- 데이콘
- dacon
- 파이썬
- PYTHON
- 자연어처리
- leetcode
- 금융문자분석경진대회
- 캐치카페
- gs25
- 편스토랑 우승상품
- 프로그래머스 파이썬
- Kaggle
- Today
- Total
목록
반응형
Programming (1169)
솜씨좋은장씨
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202" Example 2: Input: -7 Output: "-10" Note: The input will be in range of [-1e7, 1e7]. Solution class Solution: def convertToBase7(self, num: int) -> str: if num == 0: return str(num) sign = 1 if num < 0: sign = -1 num = abs(num) answer = '' while num: answer = str(num % 7) + answer num //= 7 return ('-' ..
Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn]. Return the array in the form [x1,y1,x2,y2,...,xn,yn]. Example 1: Input: nums = [2,5,1,3,4,7], n = 3 Output: [2,3,5,4,1,7] Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7]. Example 2: Input: nums = [1,2,3,4,4,3,2,1], n = 4 Output: [1,4,2,3,3,2,4,1] Example 3: Input: nums =..
An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is monotone increasing if for all i
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. Example: Input: 38 Output: 2 Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. Follow up: Could you do it without any loop/recursion in O(1) runtime? Solution class Solution: def addDigits(self, num: int) -> int: while True: if num // 10 < 1: return n..
Given a fixed length array arr of integers, duplicate each occurrence of zero, shifting the remaining elements to the right. Note that elements beyond the length of the original array are not written. Do the above modifications to the input array in place, do not return anything from your function. Example 1: Input: [1,0,2,3,0,4,5,0] Output: null Explanation: After calling your function, the inp..
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. Example 1: Input: digits = "23" Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] Example 2: Input: digits = ""..
Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1], nums2 = [2,2] Output: [2,2] Example 2: Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4] Output: [4,9] Note: Each element in the result should appear as many times as it shows in both arrays. The result can be in any order. Follow up: What if the given array is already sorted? How would you optimize ..
Implement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking. Your class will have the method, book(int start, int end). Formally, this represents a booking on the half open interval [start, end), the range of real numbers x such that start
Given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0. Consider a list of all factors of n sorted in ascending order, return the kth factor in this list or return -1 if n has less than k factors. Example 1: Input: n = 12, k = 3 Output: 3 Explanation: Factors list is [1, 2, 3, 4, 6, 12], the 3rd factor is 3. Example 2: Input: n = 7, k = 2 Output..
We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess. You call a pre-defined API int guess(int num), which returns 3 possible results: -1: The number I picked is lower than your guess (i.e. pick > num). 1: The number I ..
Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 Output: 00111001011110000010100101000000 Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000. Example 2: Input: 11111111111111111111111111111101 Outp..
Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true Follow up: Could you do it in O(n) time and O(1) space? Solution # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def isPalindrome(self, head: ListNode) -> bool..
Remove all elements from a linked list of integers that have value val. Example: Input: 1->2->6->3->4->5->6, val = 6 Output: 1->2->3->4->5 Solution # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def removeElements(self, head: ListNode, val: int) -> ListNode: while head and head.val == val: head = ..
Given alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits). You have to find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent characters have the same type. Return the reformatted string or return an empty string if it is impossible to reformat the s..
Students are asked to stand in non-decreasing order of heights for an annual photo. Return the minimum number of students that must move in order for all students to be standing in non-decreasing order of height. Notice that when a group of students is selected they can reorder in any possible way between themselves and the non selected students remain on their seats. Example 1: Input: heights =..
Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times. You examine the typed characters of the keyboard. Return True if it is possible that it was your friends name, with some characters (possibly none) being long pressed. Example 1: Input: name = "alex", typed = "aaleex" Output: true ..
Given two strings a and b, return the minimum number of times you should repeat string a so that string b is a substring of it. If it is impossible for b to be a substring of a after repeating it, return -1. Notice: string "abc" repeated 0 times is "", repeated 1 time is "abc" and repeated 2 times is "abcabc". Example 1: Input: a = "abcd", b = "cdabcdab" Output: 3 Explanation: We return 3 ..
Given an array of integers arr, write a function that returns true if and only if the number of occurrences of each value in the array is unique. Example 1: Input: arr = [1,2,2,1,1,3] Output: true Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences. Example 2: Input: arr = [1,2] Output: false Example 3: Input: arr = [-3,0,1,-3,1,1,1,..
There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves. The move sequence is represented by a string, and the character moves[i] represents its ith move. Valid moves are R (right), L (left), U (up), and D (down). If the robot returns to the origin after it finishes all of its moves..
Python에서 문자열을 다루다보면 특히 한글이 포함된 문자열을 다루게 되면 종종 아래와 같은 에러코드를 만나며 인코딩 문제로 애를 먹는 경우가 많이 있습니다. UnicodeEncodeError: 'cp949' codec can't encode character '\xa0' in position 17678: illegal multibyte sequence 위와 같은 문제를 만났을 때 내가 지금 다루고 있는 문자열 또는 파일속의 데이터가 어떤 인코딩을 사용하는지 확인하고 싶을 경우 방법은 다음과 같습니다. 필요 라이브러리 설치 먼저 인코딩을 확인하기 위해 필요한 chardet 라이브러리를 설치합니다. $ pip install chardet 사용 방법 문자열의 경우 import chardet string =..
가끔씩 데이터를 수집하기 위해서 Python으로 Selenium 을 활용한 크롤링 코드를 작성하고 실행하려하면! 새롭게 세팅한 개발환경이라 webdriver가 아직 존재하지 않거나 기존 컴퓨터에서 사용하고 있는 Chrome( 크롬 )의 버전이 업데이트 되어 기존에 사용하던 webdriver가 버전이 맞지않아 사용이 불가한 경우 직접 Chrome 버전이 무엇인지 확인 후 webdriver를 다운받는 홈페이지로 이동하여 직접 현재 버전에 맞는 파일을 다운로드 받아 사용해야 해서 번거로움이 많았습니다. 여러 페이지의 크롤러를 만들면서 이를 하나로 묶어서 패키지화를 하면 어떨까 고민하던 중 매번 다운로드 받아야하는 webdriver를 python 코드를 활용해 자동으로 설치해주면 어떨까? 라는 생각이 들었고 이..
Folium이 업데이트를 하면서 jupyter notebook 에서 지도에 시각화를 할때 한글을 출력하려고 하면 한글이 아닌 외계어가 출력되는 경우를 볼 수 있습니다. 이를 해결하는 방법은 두 가지가 있습니다. 현재 제가 해결한 Folium 라이브러리의 버전은 0.11.0 버전입니다. 버전 확인은 pip list 명령어를 통해 확인하면 됩니다. 해결방법 1 branca 라이브러리 수정 사항 반영 $ pip install git+https://github.com/python-visualization/branca.git@master
Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Your KthLargest class will have a constructor which accepts an integer k and an integer array nums, which contains initial elements from the stream. For each call to the method KthLargest.add, return the element representing the kth largest elemen..
Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible. You can use each character in text at most once. Return the maximum number of instances that can be formed. Example 1: Input: text = "nlaebolko" Output: 1 Example 2: Input: text = "loonbalxballpoon" Output: 2 Example 3: Input: text = "leetcode" Output: 0 Constraints: 1
The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in repetition of one number and loss of another number. Given an array nums representing the data status of this set after the error. Your task is to firstly find the number occurs twice and then find the number that..
Write a function that takes an unsigned integer and return the number of '1' bits it has (also known as the Hamming weight). Example 1: Input: 00000000000000000000000000001011 Output: 3 Explanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits. Example 2: Input: 00000000000000000000000010000000 Output: 1 Explanation: The input binary string 0000000000000..
Design a HashSet without using any built-in hash table libraries. To be specific, your design should include these functions: add(value): Insert a value into the HashSet. contains(value) : Return whether the value exists in the HashSet or not. remove(value): Remove a value in the HashSet. If the value does not exist in the HashSet, do nothing. Example: MyHashSet hashSet = new MyHashSet(); hashSe..
Given an integer array arr. You have to sort the integers in the array in ascending order by the number of 1's in their binary representation and in case of two or more integers have the same number of 1's you have to sort them in ascending order. Return the sorted array. Example 1: Input: arr = [0,1,2,3,4,5,6,7,8] Output: [0,1,2,4,8,3,5,6,7] Explantion: [0] is the only integer with 0 bits. [1,2..
for 문을 한 줄로 작성하는 방법 ex ) 여러개의 단어가 들어있는 리스트 중에서 길이가 3 이상인 단어만 남기고 싶을 경우 words = ["솜씨좋은장씨", "티스토리", "블로그", "파이썬", "for", "프로그래밍", "반복"] new_words = [ "솜씨좋은장씨", "티스토리", "프로그래밍" ] 기존 코드 new_words = [] for word in words: if len(word) > 3: new_words.append(word) 한 줄로 작성 new_words = [ word for word in words if len(word) > 3 ] 이중 for 문을 한 줄로 작성하는 방법 ex ) 여러 단어들이 담겨있는 2차원 리스트에서 각 리스트 별로 길이가 4 이상인 단어만 남기고..
Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false. Example 1: Input: arr = [2,6,4,1] Output: false Explanation: There are no three consecutive odds. Example 2: Input: arr = [1,2,34,3,4,5,7,23,12] Output: true Explanation: [5,7,23] are three consecutive odds. Constraints: 1