일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 캐치카페
- Real or Not? NLP with Disaster Tweets
- Kaggle
- PYTHON
- Git
- 프로그래머스
- 프로그래머스 파이썬
- 백준
- 맥북
- 자연어처리
- hackerrank
- Docker
- Baekjoon
- 편스토랑
- 코로나19
- leetcode
- dacon
- 데이콘
- ChatGPT
- gs25
- 편스토랑 우승상품
- ubuntu
- 파이썬
- AI 경진대회
- github
- programmers
- SW Expert Academy
- 우분투
- 더현대서울 맛집
- 금융문자분석경진대회
- Today
- Total
목록
반응형
2020/06 (37)
솜씨좋은장씨
Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die. Given a flowerbed (represented as an array containing 0 and 1, where 0 means empty and 1 means not empty), and a number n, return if n new flowers can be planted in it without violating the no-adjacent-f..
1일 1문제 144일차! 오늘의 문제는 Base Conversion입니다. 11576번: Base Conversion 타임머신을 개발하는 정이는 오랜 노력 끝에 타임머신을 개발하는데 성공하였다. 미래가 궁금한 정이는 자신이 개발한 타임머신을 이용하여 500년 후의 세계로 여행을 떠나게 되었다. 500년 후의 www.acmicpc.net Solution A, B = map(int, input().split()) m = int(input()) num = list(map(int, input().split())) result = [] n = 0 for i in range(len(num)): n = n + (num.pop() * (A**i)) while n: result.append(n%B) n //= B whi..
MNIST 데이터를 활용하여 손글씨 분류를 해보기 위해서 Tensorflow 2.0을 활용하여 모델을 만들고 model.fit을 실행하였는데 ValueError: Shapes (32, 10) and (32, 1) are incompatible 위와 같은 에러가 발생하였습니다. 처음에는 데이터 전처리를 잘못한 것으로 생각하다가 아무리 봐도 데이터 전처리에 있어서는 문제가 없어 보여서 찾아보니 sparse_categorical_crossentropy를 loss사용하여 model을 compile할 때 metrics 에서 충돌이 일어나 발생하는 문제였습니다. 해결 방법은 아래와 같습니다. 에러가 발생하던 compile 방법 model.compile(optimizer=tf.keras.optimizers.Adam(..
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one. Example 1: Input: [1,3,4,2,2] Output: 2 Example 2: Input: [3,1,3,4,2] Output: 3 Note: You must not modify the array (assume the array is read only). You must use only constant,..
1일 1문제 142일차! 142일차의 문제는 진법 변환 2입니다. 11005번: 진법 변환 2 10진법 수 N이 주어진다. 이 수를 B진법으로 바꿔 출력하는 프로그램을 작성하시오. 10진법을 넘어가는 진법은 숫자로 표시할 수 없는 자리가 있다. 이런 경우에는 다음과 같이 알파벳 대문자를 �� www.acmicpc.net Solution B_jinbub_dic = { 0:'0', 1:'1', 2:'2', 3:'3', 4:'4', 5:'5', 6:'6', 7:'7', 8:'8', 9:'9', 10:'A', 11:'B', 12:'C', 13:'D', 14:'E', 15:'F', 16:'G', 17:'H', 18:'I', 19:'J', 20:'K', 21:'L', 22:'M', 23:'N', 24:'O', 25..
1일 1문제 141일차! 141일차의 문제는 백준의 가장 큰 증가 부분 수열입니다. 11055번: 가장 큰 증가 부분 수열 수열 A가 주어졌을 때, 그 수열의 증가 부분 수열 중에서 합이 가장 큰 것을 구하는 프로그램을 작성하시오. 예를 들어, 수열 A = {1, 100, 2, 50, 60, 3, 5, 6, 7, 8} 인 경우에 합이 가장 큰 증가 부분 수� www.acmicpc.net Solution inputNum = int(input()) inputNums = input() inputNums = inputNums.split() inputNums = [int(num) for num in inputNums] nc = [0] * (inputNum) maxNum = 0 for i in range(0, in..
1일 1문제 140일차! 140일차의 문제는 백준의 가장 긴 바이토닉 부분 수열 입니다. 11054번: 가장 긴 바이토닉 부분 수열 첫째 줄에 수열 A의 크기 N이 주어지고, 둘째 줄에는 수열 A를 이루고 있는 Ai가 주어진다. (1 ≤ N ≤ 1,000, 1 ≤ Ai ≤ 1,000) www.acmicpc.net Solution import sys r = lambda : sys.stdin.readline() def _get_seq_len(a): dp = [1 for _ in range(len(a))] rev_dp = [1 for _ in range(len(a))] for i in range(len(a)): dp[i] = 1 for j in range(i, -1, -1): if a[i] > a[j] and..
1일 1문제 139일차! 139일차의 문제는 백준의 카드 구매하기 입니다. 11052번: 카드 구매하기 첫째 줄에 민규가 구매하려고 하는 카드의 개수 N이 주어진다. (1 ≤ N ≤ 1,000) 둘째 줄에는 Pi가 P1부터 PN까지 순서대로 주어진다. (1 ≤ Pi ≤ 10,000) www.acmicpc.net Solution cardNum = int(input()) NC = [0]*(cardNum+1) cardPrice = [0]+list(map(int, input().split())) def answer(): NC[0], NC[1] = 0, cardPrice[1] for i in range(2, cardNum+1): for j in range(1, i+1): NC[i] = max(NC[i], NC[i..
어제 WWDC에서 macOS Big Sur가 공개되고 Beta버전을 사용해볼 수 있게 됨에 따라 항상 Beta버전 OS 부터 사용해보던 저는 평소와 같이 Profile을 다운로드 받아서 설치를 시작했습니다. 그런데 무난하게 설치가 진행되는 것 같던 중 위와 같은 화면에서 4시간 가량 더이상 진행되지 않는 현상이 있었습니다. 이에 재부팅을 하면서 Command + R을 눌러 복구모드로 진입하였고 복구모드에서 업데이트 로그를 확인해보니 Macbook-Pro configd[40] : DHCP en6 INIT transmit failed 위와 같은 오류가 계속 발생하고 있었습니다. 이를 해결하는 방법은 다음과 같습니다. 먼저 디스크 유틸리티 메뉴에서 모든 디스크 검사/복구를 실시합니다. 먼저 상단 바에서 유틸리..
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element always exist in the array. Example 1: Input: [3,2,3] Output: 3 Example 2: Input: [2,2,1,1,1,2,2] Output: 2 Solution class Solution: def majorityElement(self, nums: List[int]) -> int: keys = set(nums) ans..
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.Now, given an integer n, write a function that returns true when it is a perfect number and false when it is not. Example: Input: 28 Output: True Explanation: 28 = 1 + 2 + 4 + 7 + 14 Note: The input number n will not exceed 100,000,000. (1e8) Solution import math class Solution(..
Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and left the other as original. Example: Input: s = "abcdefg", k = 2 Output: "bacdfeg" Rest..
Comparators are used to compare two objects. In this challenge, you'll create a comparator and use it to sort an array. The Player class is provided in the editor below. It has two fields: name : a string. score : an integer. Given an array of n Player objects, write a comparator that sorts them in order of decreasing score. If 2 or more players have the same score, sort those players alphabetic..
Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5 Example 2: Input: 3 Output: False Solution class Solution: def judgeSquareSum(self, c): for i in range(0,int(c**0.5)+1): extra=c-pow(i, 2) if (pow(int(extra**0.5),2)) == extra: return True return False SOMJANG/CODINGTE..
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Example: Input: [0,1,0,3,12] Output: [1,3,12,0,0] Note: You must do this in-place without making a copy of the array. Minimize the total number of operations. Solution class Solution: def moveZeroes(self, nums): for i in range(len(nums))[::-1]: if nums[i] == 0: nu..
문자열 표현 방법 var a = '작은 따옴표 활용'; var b = "큰 따옴표 활용"; 작은 따옴표 또는 큰 따옴표로 묶어서 표현 작은 따옴표 표현 방법 var c = "큰 따옴표 안에 작은 따옴표 ' 사용"; var d = "역슬래시를 활용하여 표현 \' 할수도 있음"; var d = '역슬래시를 활용하여 표현 \' 할수도 있음'; 큰 따옴표로 묶은 후 그 안에 작은 따옴표를 활용하는 방법과 역슬래시를 활용하는 방법 두 가지 존재 큰 따옴표 표현 방법 var e = '작은 따옴표 안에 큰 따옴표 " 사용'; var f = "역슬래시를 활용하여 표현 \" 할수도 있음"; var f = '역슬래시를 활용하여 표현 \" 할수도 있음'; 작은 따옴표로 묶은 후 그 안에 큰 따옴표를 활용하는 방법과 역슬래시..
평소에 공부하면서 딥러닝에 대한 기초적인 개념은 까먹고 있는 것 같아 패스트 캠퍼스의 강의를 통해 딥러닝에 대해서 처음부터 차근차근 다시 살펴보며 공부하기로 하였습니다. 앞으로 강의를 듣고 강의에서 기억했으면 좋겠다 하는 내용에 대해서 하나씩 적어보려합니다. 딥러닝의 전체 구조 딥러닝의 구조를 간단하게 살펴보면 Data를 Model에 넣고 예측 (Logit) 하고 예측한 값에 대해서 얼마나 틀렸는지 (Loss, 오류율)를 계산 한 후 이 오류율을 최소화하는 작업(Optm)을 거쳐 다시 그 값을 Model에 넣고 Loss가 최소화 될때까지 반복한 뒤 결과(Result)를 도출하는 방식입니다. 학생이 문제집을 풀었을때 틀린 갯수가 가장 적어지기 위해서 공부를 하는 것에 비유를 들어보면 학생이 문제집을 사서(..
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid. Example 1: Input: "()" Output: true Example 2: Input: "()[]{}" Output: true Example 3: I..
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define empty string as valid palindrome. Example 1: Input: "A man, a plan, a canal: Panama" Output: true Example 2: Input: "race a car" Output: false Solution import re class Solution: def isPalindrome(self, s: str) -> bool: s = s.lower() text = ..
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Solution from collections import Counter class Solution: def firstUniqChar(self, s: str) -> int: answer = -1 s = list(s) cnt_dict = Counter(s) i = 0 for word in s: if cnt_dict[word] == 1: answer = i break i = i + 1 re..
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. Example: Input: nums1 = [1,2,3,0,0,0], m = 3 nums2 = [2,5,6], n = 3 Output: [1,2,2,3,5,6] Solut..
Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,1] Output: 1 Example 2: Input: [4,1,2,1,2] Output: 4 Solution from collections import Counter class Solution: def singleNumber(self, nums: List[int]) -> int: c..
Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”. Example: n = 15, Return: [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz..
Python으로 프로그래밍을 하다보면 가끔 아래와 같은 오류를 만나는 경우가 있습니다. SyntaxError: Non-ASCII character '\xeb' in file 위의 오류는 코드 내부에 한글 데이터가 포함 되어있을 경우 발생하는 문제입니다. 이걸 해결하기 위해서 코드에 있는 한글을 다 삭제하거나 영어로 번역하지 않아도 됩니다. 해결방법 #-*- coding:utf-8 -*- 해당 코드파일의 코드 맨 윗줄에 위의 코드를 추가해주고 다시 실행해보면 정상적으로 작동하는 것을 볼 수 있습니다! 읽어주셔서 감사합니다!
Given an array of integers A, consider all non-empty subsequences of A. For any sequence S, let the width of S be the difference between the maximum and minimum element of S. Return the sum of the widths of all subsequences of A. As the answer may be very large, return the answer modulo 10^9 + 7. Example 1: Input: [2,1,3] Output: 6 Explanation: Subsequences are [1], [2], [3], [2,1], [2,3], [1,3]..
We say that a string contains the word hackerrank if a subsequence of its characters spell the word hackerrank. For example, if string s = haacckkerrannkk it does contain hackerrank, but s = haacckkerannk does not. In the second case, the second r is missing. If we reorder the first string as hccaakkerrannkk, it no longer contains the subsequence due to ordering. More formally, let p[0], p[1], ...
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. Example 1: Input: [3,0,1] Output: 2 Example 2: Input: [9,6,4,2,3,5,7,0,1] Output: 8 Note: Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity? Solution class Solution: def missingNumber(self, nums: List[int]) -..
Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. You may assume all the characters consist of printable ascii characters. Example 1: Input: ["h","e","l","l","o"] Output: ["o","l","l","e","h"] Example 2: Input: ["H","a","..
Flask로 웹페이지를 만들면서 npm 라이브러리를 사용해야하는 경우 다음과 같은 방법으로 사용하면 됩니다. 다음의 방법은 node.js가 미리 설치되어있다는 가정 하에 가능합니다. Mac을 사용하고 brew를 설치하셨다면 $ brew install node 위의 명령어를 활용하여 설치하여 줍니다. 먼저 Flask 프로젝트의 static 디렉토리로 이동합니다. $ cd static 그 다음 다음의 명령어를 활용하여 npm 프로젝트로 initialize 시켜줍니다. $ npm init 그 다음 npm라이브러리 중 사용을 희망하는 라이브러리를 설치하고 저장합니다. 예시로는 dom-inspector라는 오픈소스 라이브러리를 예시로 들겠습니다. $ npm install dom-inspector --save 완료..
Given an integer, write a function to determine if it is a power of three. Example 1: Input: 27 Output: true Example 2: Input: 0 Output: false Example 3: Input: 9 Output: true Example 4: Input: 45 Output: false Follow up: Could you do it without using any loop / recursion? Solution class Solution: def isPowerOfThree(self, n: int) -> bool: return n > 0 and pow(3, 31, n) == 0 SOMJANG/CODINGTEST_PR..