TIL/Coding Test

    [LeetCode] Lemonade Change

    오늘의 문제. 문제 이름이 맘에 든다. 레모네이드 거스름돈! At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bills). Each customer will only buy one lemonade and pay with either a $5, $10, or $20 bill. You must provide the correct change to each customer, so that the net transaction is that the customer pays $5. Note that yo..

    [LeetCode] Two Sum

    오늘의 문제. Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.You may assume that each input would have exactly one solution, and you may not use the same element twice.You can return the answer in any order. 정수 배열인 nums와 정수 target이 주어진다. 더하면 target값이 되는 두 숫자의 인덱스를 리턴하라.한가지 배열 요소를 두 번 이상 사용하지 않는다. 솔루션은 하나뿐이라고 가정할 수 있다. 답안을 어떤 순서대..

    [LeetCode] Top K Frequent Elements

    오늘의 문제 문제를 읽어보며 예상하긴 했지만 구글링 없이 현재의 내 능력으론 절대 풀 수 없는 문제였다. Top K Frequent Elements - 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 시도해 본 흔적. import java.util.HashMap; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; /*Given a non-empty array of integers..

    [LeetCode] Roman to Integer

    오느릐 문제. 로마 숫자를 정수형태로 바꿔보기. leetcode.com/problems/roman-to-integer/ Roman 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 cote0312_13_RomanToInteger { public int romanToInt(String s) { //s의 길이를 알아야겠징 int[] iArr=new ..

    [LeetCode] Path Sum

    오늘의 문제. leaf까지의 노드값 총합이, 주어진 targetSum과 같은 경우가 있는지 구하시오. Path Sum - 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 TreeNode { int val; TreeNode left; TreeNode right; TreeNode() {} TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left, TreeNode right) { this.v..

    [LeetCode] Binary Tree Inorder Traversal

    오늘의 문제는 이진 트리 구현해보기. 전에 멘토 언니가 공부한 담에 꼭 손으로 구현해 보세요, 라고 했는데 혼자선 안 할 거 같아서 냉큼 문제로 올렸다. leetcode.com/explore/interview/card/top-interview-questions-medium/108/trees-and-graphs/786/ 처음 삽질한 흔적. 아.. 길다... public class cote0310_786_BinaryTreeInorderTraversal { //Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode() {} TreeNode(int val) { this.val..

    [LeetCode] Reverse String

    오늘의 문제 2. 빛줄기 언니가 다른 문제를 하나 더 내줬다. 전에 풀었던 문제랑 푸는 방법이 비슷했다. 간략하게 설명하자면 char 요소들로 이루어진 배열을 거꾸로 뒤집는 문제. Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com public class cote0309_250_principleOfRecursion_1440_ReverseString { pu..

    [LeetCode] Divisor Game

    오늘의 문제는 일종의 숫자 게임의 규칙을 알아내야 하는 문제였다. leetcode.com/problems/divisor-game/ Divisor Game - 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 /* Alice and Bob take turns playing a game, with Alice starting first. Initially, there is a number N on the chalkboard. On each player's turn, th..

    [LeetCode] Fibonacci Number

    오늘은 피보나치 배열. 재귀함수는 늘 헷갈린다. 이러는게 맞나? 이래도 되나? 그런 느낌. Fibonacci Number - 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 처음 푼 방법 - 재귀함수 써보기. 런타임이 7~8ms 나왔다. class Solution { public int fib(int n) { if(n

    [LeetCode] Sort Colors

    오늘의 문제는 빨강 하양 파랑의 3색을 순서대로 소팅하기. Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 아래 두 가지 추가 요건이 있었다. sort함수를 쓰지 않고 풀 수 있는가? O(1)로 풀 수 있는가? public class cote0305_sort_color { /* Given an array nums with n objects colored..