일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 데이콘
- AI 경진대회
- 캐치카페
- leetcode
- 금융문자분석경진대회
- hackerrank
- programmers
- Real or Not? NLP with Disaster Tweets
- 편스토랑
- SW Expert Academy
- Baekjoon
- ubuntu
- 백준
- 코로나19
- Git
- 맥북
- 자연어처리
- Docker
- ChatGPT
- 편스토랑 우승상품
- gs25
- github
- 더현대서울 맛집
- dacon
- 프로그래머스
- 우분투
- Kaggle
- 파이썬
- 프로그래머스 파이썬
- PYTHON
- Today
- Total
목록
반응형
Programming (1169)
솜씨좋은장씨
Given a positive integer n, you can apply one of the following operations: If n is even, replace n with n / 2. If n is odd, replace n with either n + 1 or n - 1. Return the minimum number of operations needed for n to become 1. Example 1: Input: n = 8 Output: 3 Explanation: 8 -> 4 -> 2 -> 1 Example 2: Input: n = 7 Output: 4 Explanation: 7 -> 8 -> 4 -> 2 -> 1 or 7 -> 6 -> 3 -> 2 -> 1 Example 3: I..
In a given integer array nums, there is always exactly one largest element. Find whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, otherwise return -1. Example 1: Input: nums = [3, 6, 1, 0] Output: 1 Explanation: 6 is the largest integer, and for every other number in the array x, 6 is more th..
Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to B, otherwise, return false. Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at A[i] and A[j]. For example, swapping at indices 0 and 2 in "abcd" results in "cbad". Example 1: Input: A = "ab", B = "ba" Output: tru..
Given an array of integers arr, a lucky integer is an integer which has a frequency in the array equal to its value. Return a lucky integer in the array. If there are multiple lucky integers return the largest of them. If there is no lucky integer return -1. Example 1: Input: arr = [2,2,3,4] Output: 2 Explanation: The only lucky number in the array is 2 because frequency[2] == 2. Example 2: Inpu..
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]). You are given a target value to search. If found in the array return true, otherwise return false. Example 1: Input: nums = [2,5,6,0,0,1,2], target = 0 Output: true Example 2: Input: nums = [2,5,6,0,0,1,2], target = 3 Output: false Follow up: This i..
Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the matrix. Example 1: Input: [[1,2,3],[4,5,6],[7,8,9]] Output: [[1,4,7],[2,5,8],[3,6,9]] Example 2: Input: [[1,2,3],[4,5,6]] Output: [[1,4],[2,5],[3,6]] Note: 1
pandas를 활용하여 읽어온 csv 파일에서 특정 column에 대한 중복값을 제거하기 위하여 아래와 같이 먼저 파일을 엑셀에서 읽어온 후 import pandas as pd data = pd.read_excel("./42_nia_pqa_QueryTemplate.xlsx") data_fillna = data.fillna(0.0) data_fillna_dropna = data_fillna[data_fillna['property'] != 0.0] data_fillna_dropna.head() 특정 값 이외의 값만 남기기 위하여 위와 같이 코드를 실행하였으나 --------------------------------------------------------------------------- ValueErr..
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Note: You must not use any built-in BigInteger library or convert the inputs to integer directly. Example 1: Input: num1 = "2", num2 = "3" Output: "6" Example 2: Input: num1 = "123", num2 = "456" Output: "56088" Constraints: 1 123으로 바뀌게 됩니다. 그럼 이렇게 바꾼 숫자를 곱하고 s..
Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing so, return the array. Example 1: Input: arr = [17,18,5,4,6,1] Output: [18,6,6,6,1,-1] Constraints: 1
Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1. Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Elements that don't appear in arr2 should be placed at the end of arr1 in ascending order. Example 1: Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6] Output: [2,2,2,1,4,3,3,9,..
Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time. Return that integer. Example 1: Input: arr = [1,2,2,6,6,6,6,7,10] Output: 6 Constraints: 1
최근 약 3만개의 한글파일을 첫페이지를 이미지로 500x707크기의 썸네일을 만들어야하는 일이 있었습니다. 30개의 파일이었으면 귀찮더라도 그냥 모든 파일을 하나하나 열어서 첫 페이지를 이미지로 저장하게끔 하였겠지만 3만개의 파일을 하나하나 열어서 하기에는 너무 많은 양이 었습니다. 저는 이를 파이썬으로 코드를 작성하여 한번에! 촤르륵 실행해보기로 하였습니다. 파이썬을 배우고 나서부터는 이런 대량의 파일을 다루는 작업이나 단순 반복 작업, 수많은 파일 속에서 하나의 파일 찾기와 같은 작업을 주로 파이썬을 활용하여 진행하게 되는 것 같습니다. 진행한 환경은 Windows 10 + 한글 2018 + Python3,7 ( pywin32 라이브러리 ) 에서 진행하였습니다. 이 작업을 진행하기 위해서는 무조건! ..
한글 파일에서 첫 페이지만 bmp로 저장한 다음 bmp 파일을 작은 해상도로 resizing 한 후 jpeg로 저장하는 과정에서 이미지가 깨져서 보이는 현상이 있었습니다. 처음에는 한글 API 가 제대로 동작하지 않아서인가 싶었지만 PIL(Pillow) 라이브러리에서 resize 하는 과정에서 발생하는 문제였습니다. 해결 방법 해결하는 방법은 아주 간단했습니다. img = Image.open("./test.bmp").convert("RGB") new_img = img.resize((500, 707), Image.ANTIALIAS) new_img.save("./test.jpg", format='jpeg', quality=100) resize를 하는 과정에서 Image.ANTIALIAS 라는 인자를 넣어주면..
Given a m * n matrix of distinct numbers, return all lucky numbers in the matrix in any order. A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column. Example 1: Input: matrix = [[3,7,8],[9,11,13],[15,16,17]] Output: [15] Explanation: 15 is the only lucky number since it is the minimum in its row and the maximum in its column Example 2..
Given a m * n matrix grid which is sorted in non-increasing order both row-wise and column-wise. Return the number of negative numbers in grid. Example 1: Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]] Output: 8 Explanation: There are 8 negatives number in the matrix. Example 2: Input: grid = [[3,2],[1,0]] Output: 0 Example 3: Input: grid = [[1,-1],[-1,-1]] Output: 3 Example 4: ..
업무 중 NER을 담당하는 분께 NER을 활용하여 특정 태스크에 대해서 테스트를 요청드렸었고 결과로 받은 파일은 'INPUT : 롤플레잉 게임 시스템 쇼크를 개발한 회사는\n', "GOLD : ['O', 'O', 'B-SUB', 'I-SUB', 'O', 'O']\n", "PRED : ['B-EXP', 'I-EXP', 'B-SUB', 'I-SUB', 'O', 'O']\n", 'CONF : [0.99205834 0.99542373 0.9999639 0.999987 0.99999595 0.9999968 ]\n', 이렇게 NER을 거쳐 나온 결과들이 string 형식으로 한줄한줄 적혀 있는 txt 파일 형식이었습니다. 여기서 NER 모델이 예측해서 뽑아낸 결과를 B-SUB, I-SUB, B-EXP, I-EXP를..
The Tribonacci sequence Tn is defined as follows: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0. Given n, return the value of Tn. Example 1: Input: n = 4 Output: 4 Explanation: T_3 = 0 + 1 + 1 = 2 T_4 = 1 + 1 + 2 = 4 Example 2: Input: n = 25 Output: 1389537 Constraints: 0
The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, F(0) = 0, F(1) = 1 F(N) = F(N - 1) + F(N - 2), for N > 1. Given N, calculate F(N). Example 1: Input: 2 Output: 1 Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1. Example 2: Input: 3 Output: 2 Explanation: F(3) = F(2) ..
You are given a license key represented as a string S which consists only alphanumeric character and dashes. The string is separated into N+1 groups by N dashes. Given a number K, we would want to reformat the strings such that each group contains exactly K characters, except for the first group which could be shorter than K, but still must contain at least one character. Furthermore, there must..
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k. Example 1: Input: nums = [1,2,3,1], k = 3 Output: true Example 2: Input: nums = [1,0,1,1], k = 1 Output: true Example 3: Input: nums = [1,2,3,1,2,3], k = 2 Output: false Solution class Solution: def..
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. Example 1: Input: [1,2,3,1] Output: true Example 2: Input: [1,2,3,4] Output: false Example 3: Input: [1,1,1,3,3,4,3,2,4,2] Output: true Solution from collections import Counter class Solu..
Given a list of non-negative integers nums, arrange them such that they form the largest number. Note: The result may be very large, so you need to return a string instead of an integer. Example 1: Input: nums = [10,2] Output: "210" Example 2: Input: nums = [3,30,34,5,9] Output: "9534330" Example 3: Input: nums = [1] Output: "1" Example 4: Input: nums = [10] Output: "10" Constraints: 1
Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you leave beyond the new length. Clarification: Confused why the returned value is an integer but your ..
Find all valid combinations of k numbers that sum up to n such that the following conditions are true: Only numbers 1 through 9 are used. Each number is used at most once. Return a list of all possible valid combinations. The list must not contain the same combination twice, and the combinations may be returned in any order. Example 1: Input: k = 3, n = 7 Output: [[1,2,4]] Explanation: 1 + 2 + 4..
Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both? Solution # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def reverseList(self, head: ListNode) -> ListN..
Given words first and second, consider occurrences in some text of the form "first second third", where second comes immediately after first, and third comes immediately after second. For each such occurrence, add "third" to the answer, and return the answer. Example 1: Input: text = "alice is a good girl she is a good student", first = "a", second = "good" Output: ["girl","student"] Example 2: ..
Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: "tree" Output: "eert" Explanation: 'e' appears twice while 'r' and 't' both appear once. So 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer. Example 2: Input: "cccaaa" Output: "cccaaa" Explanation: Both 'c' and 'a' appear three times, so "aaaccc" is also a valid an..
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example 1: Input: [3,2,1,5,6,4] and k = 2 Output: 5 Example 2: Input: [3,2,3,1,2,4,5,5,6] and k = 4 Output: 4 Note: You may assume k is always valid, 1 ≤ k ≤ array's length. Solution class Solution: def findKthLargest(self, nums: List[int], k: int) -> int:..
Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1] Note: You may assume k is always valid, 1 ≤ k ≤ number of unique elements. Your algorithm's time complexity must be better than O(n log n), where n is the array's size. It's guaranteed that the answer is unique, in o..
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twice in this array. Could you do it without extra space and in O(n) runtime? Example: Input: [4,3,2,7,8,2,3,1] Output: [2,3] Solution from collections import Counter class Solution: def findDuplicates(self, nums: List[int]) -> List[int]: cnt_items = ..