TIL/Coding Test

    [LeetCode] Reverse Linked List

    오늘의 문제. recursive를 뿌셔보기로 했는데 뿌셔지는 것은 나.. Reverse Linked List - 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 LinkedList를 거꾸로 뒤바꾸는 문제였다. 재귀는 생각이 안 나서 일단 temp를 설정해서 바꾸는 걸 시도했는데 포인터로 다음 노드를 가리키기 때문에 내가 생각했던 것보다 조금 더 복잡한 작업이 필요했다. class ListNode { int val; ListNode next; ListNode() {..

    [LeetCode] Convert Binary Number in a Linked List to Integer

    오늘의 문제. 링크드리스트에 들어 있는 이진수를 십진수로 바꿔라. Convert Binary Number in a Linked List to Integer - 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 일단 자바로 한 번 풀고 public class cote0405_1290_ConvertBinaryNumberInALinkedListToInteger { public class ListNode { int val; ListNode next; ListNode() {..

    [LeetCode] assign cookies (Python)

    풀었던 문제를 파이썬으로 다시 풀어보기. 분명 풀었던 문제임에도 낯설다... Assign Cookies - 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 from typing import List class cote0401_455_assignCookies: def findContentChildren(self, g: List[int], s: List[int]) -> int: g.sort() s.sort() index=0 count=0 for i in range(l..

    [LeetCode] Two Sum (Python)

    오늘은 JAVA로 풀었던 Two Sum을 Python으로 풀어보기 연습. 은 사실 어제 문제였지만.. 그리고 '다시 푼다'기 보단 자바 코드를 파이썬 코드로 옮기는 것에 가까운 것 같다. 이것도 생각보다 노력이 필요한 일이긴 하다... class Solution: #used Dictionary def twoSum(self, nums: List[int], target: int) -> List[int]: ansMap = {} for i in range(len(nums)): if target-nums[i] in ansMap: return [ansMap.get(target-nums[i]), i] else: ansMap[nums[i]] = i i+=1 #used double for clause def twoSum..

    [LeetCode] Lemonade Change (Python)

    이전에 풀어본 문제를 다른 언어로 풀어보기로 했다. 고랭에도 관심이 갔지만 일단 좀 더 대중화되어 있는 파이썬으로 도전! Lemonade Change - 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 class Solution: def lemonadeChange(self, bills: List[int]) -> bool: ch5=0 ch10=0 for bill in bills: if bill == 5: ch5+=1 elif bill == 10: if ch5 > 0..

    [백준] 베스트셀러 Best Seller

    3월 26일 문제였다. 1302번: 베스트셀러 첫째 줄에 오늘 하루 동안 팔린 책의 개수 N이 주어진다. 이 값은 1,000보다 작거나 같은 자연수이다. 둘째부터 N개의 줄에 책의 제목이 입력으로 들어온다. 책의 제목의 길이는 50보다 작거나 같고 www.acmicpc.net 답안 코드. import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.TreeMap; import java.util.Map.Entry; public class cote0326_Be..

    [프로그래머스] 오픈채팅방

    오늘의 문제. 카카오 2019 블라인드 채용 문제로 나온 문제인가보다. 30분엔 어림도 없지.. 60분 꽉 채워서 풀었다. 어쨌든 풀어서 기분은 좋음. 코딩테스트 연습 - 오픈채팅방 오픈채팅방 카카오톡 오픈채팅방에서는 친구가 아닌 사람들과 대화를 할 수 있는데, 본래 닉네임이 아닌 가상의 닉네임을 사용하여 채팅방에 들어갈 수 있다. 신입사원인 김크루는 카카오톡 오 programmers.co.kr import java.util.HashMap; import java.util.Map; public class cote0324_chatroom { /* ~ 의식의 흐름 ~ 유저아이디에 따라서 마지막 닉네임을 해당 닉네임으로 저장 Enter, Leave는 각각 들어왔습니다, 나갔습니다. Change는 로그만 남고 리..

    [프로그래머스] 카펫

    오느릐 문제. 내가 골랐다. 이런 식으로 그림이랑 같이 나오는 문제가 코테에 자주 나오는 것 같아서 골라보았다. 접근방법을 생각하기가 조금 어려웠지만 수식만 조금씩 수정해나가니까 계산이 맞아서 생각보다 빨리 풀렸다. 솔직히 처음 10분은 아 오늘도 못풀겠군,, 이라고 생각했음. 코딩테스트 연습 - 카펫 Leo는 카펫을 사러 갔다가 아래 그림과 같이 중앙에는 노란색으로 칠해져 있고 테두리 1줄은 갈색으로 칠해져 있는 격자 모양 카펫을 봤습니다. Leo는 집으로 돌아와서 아까 본 카펫의 노란색과 programmers.co.kr import java.util.ArrayList; import java.util.List; class cote0323_carpet{ /* ~ 의식의 흐름 ~ 브라운+옐로의 합은 가로세..

    [프로그래머스] 주식가격

    오늘의 문제. 프로그래머스 플랫폼 문제다. 오랜만에 한글 보니까 넘 반갑.. 코딩테스트 연습 - 주식가격 초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요. 제한사항 prices의 각 가격은 1 이상 10,00 programmers.co.kr 초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요. 제한사항 1. prices의 각 가격은 1 이상 10,000 이하인 자연수입니다. 2. prices의 길이는 2 이상 100,000 이하입니다. 의식의 흐름은 맞았는데 코드로..

    [LeetCode] Majority Element

    오늘의 문제. leetcode.com/problems/majority-element/ Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. 크기가 n인 정수 배열 nums가 주어진다. 가장 많은 요소를 리턴하시오. 가장 많은 요소는 n/2 이상 나타나는 요소이다. 배열에서 항상 존재한다고 가정할 수 있다. Constraints: 1. n == nums.length 2. 1