Algorithm

Programming/Algorithm

[Programmer Weekly Challenge #1] 부족한 금액 계산하기

문제 설명 새로 생긴 놀이기구는 인기가 매우 많아 줄이 끊이질 않습니다. 이 놀이기구의 원래 이용료는 price원인데, 놀이기구를 N 번 째 이용한다면 원래 이용료의 N배를 받기로 하였습니다. 즉, 처음 이용료가 100이었다면 2번째에는 200, 3번째에는 300으로 요금이 인상됩니다. 놀이기구를 count번 타게 되면 현재 자신이 가지고 있는 금액에서 얼마가 모자라는지를 return 하도록 solution 함수를 완성하세요. 단, 금액이 부족하지 않으면 0을 return 하세요. 제한사항 놀이기구의 이용료 price : 1 ≤ price ≤ 2,500, price는 자연수 처음 가지고 있던 금액 money : 1 ≤ money ≤ 1,000,000,000, money는 자연수 놀이기구의 이용 횟수 co..

Programming/Algorithm

[Queue문제] - ZigZagOrder

위와 같은 트리가 있을 때, [[1], [3, 2], [4, 5]] 의 결과를 출력하라 트리를 탐색하는데, 한번씩 방문 순서를 지그 재그 형태로 바꿔가면서 탐색을 해야 하는 문제이다. 일반적으로 트리를 preorder(전위순회)로 순회하지만, L, R 부분을 바꿔가면서 탐색하도록 해야 한다. 간단하게 boolean 타입 플래그를 두고, L와 R 노드를 방문하는 순서를 바꿔주면 된다. package inflearn.queue; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; class TreeNode { public int val; public TreeNode left;..

Programming/Algorithm

[30 Days of Code] 0: Hello, World

Objective In this challenge, we review some basic concepts that will get you started with this series. You will need to use the same (or similar) syntax to read input and write output in challenges throughout HackerRank. Check out the Tutorial tab for learning materials and an instructional video! Task To complete this challenge, you must save a line of input from stdin to a variable, print Hell..

Programming/Algorithm

[Java-알고리즘] Two Sum

[Problem] Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. [Example1] Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. [Example2] Given nums = [3, 2, 4], target = 6, Because nums[1] + num..

Programming/Algorithm

[Java-알고리즘] RangeSumBinaraySearchTree

[Problem] Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive). The binary search tree is guaranteed to have unique values. [Example1] Input: root = [10,5,15,3,7,null,18], L = 7, R = 15 Output: 32 [Example2] Input: root = [10,5,15,3,7,13,18,1,null,6], L = 6, R = 10 Output: 23 [Note] The number of nodes in the tree is at most 10..

Programming/Algorithm

[Java-알고리즘] toLowerCase Implemet

[Problem] Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase. [Example1] Input: "Hello" Output: "hello" [Example2] Input: "here" Output: "here" [Example3] Input: "LOVELY" Output: "lovely" [Solution] import java.lang.StringBuilder; class Solution { public String toLowerCase(String str) { char[] characters = str.toCharArray(); int strLen = st..

Programming/Algorithm

[Java-알고리즘] Split a String in Balanced Strings

[Problem] Balanced strings are those who have equal quantity of 'L' and 'R' characters. Given a balanced string s split it in the maximum amount of balanced strings. Return the maximum amount of splitted balanced strings. [Example1] Input: s = "RLRRLLRLRL" Output: 4 Explanation: s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'. [Example2] Input: s ..

Programming/Algorithm

[Java-알고리즘] Jewels and Stones

[Problem] You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels. The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so "a" is considered a different type of stone ..

JohnMark
'Algorithm' 태그의 글 목록