본문 바로가기

알고리즘71

[codility] Brackets BracketsDetermine whether a given string of parentheses (multiple types) is properly nested.Task Score100%Correctness100%Performance100% 오랜만에 풀어보는 코딜리티문제~!요새 스택 문제가 풀어보고싶었는데 딱 좋은 문제를 만났다. // you can also use imports, for example:import java.util.*;​// you can write to stdout for debugging purposes, e.g.// System.out.println("this is a debug message");​class Solution { public int solution(String .. 2019. 12. 11.
[LeetCode] #4 Median of Two Sorted Arrays Median of Two Sorted Arrays​xThere are two sorted arrays nums1 and nums2 of size m and n respectively.​Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).​You may assume nums1 and nums2 cannot be both empty. 중간값 (Median)을 구하라는 문제이다.홀수개일 때는 중간값을, 짝수개일때는 중간 값 2개의 평균을 반환하면 된다. xxxxxxxxxxclass Solution { public double findMedianSortedArrays(int[] nums1, .. 2019. 12. 8.
[LeetCode] #3 Longest Substring Without Repeating Characters Longest Substring Without Repeating CharactersxGiven a string, find the length of the longest substring without repeating characters. 중복되는 알파벳이 없는 가장 최장의 substring을 구하라는 문제이다.내 풀이부터 우선 보자. xclass Solution { public int lengthOfLongestSubstring(String s) { int answer = 0; String tmp = ""; for (int i = 0; i 2019. 12. 5.
[LeetCode] #1 Two Sum Two SumxGiven 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. 첫번째 문제 답게 쉬운 문제가 나왔다.그런데 뭔가 멋있게 풀고싶은 마음이 너무 드글드글해서,회사 제품 특성상 낮은 jdk버전에도 사용 가능한 코드만 짜다보니 간단하면서도 최근 jdk(라고 해봐야 자바8이지만..ㅎㅎ)에서 사용 가능한 방법으로 풀고싶었다. 그래서 우선 스트림을 사용해봤다.xxxxxxxxxximport.. 2019. 12. 5.
[codewars] Which are in? Which are in?xGiven two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2.​#Example 1: a1 = ["arp", "live", "strong"]​a2 = ["lively", "alive", "harp", "sharp", "armstrong"]​returns ["arp", "live", "strong"]​#Example 2: a1 = ["tarp", "mice", "bull"]​a2 = ["lively", "alive", "harp", "sharp", "armstrong"]​returns .. 2019. 3. 29.
[codewars] Who likes it? WhoLikeThis Who likes it?xYou probably know the "like" system from Facebook and other pages. People can "like" blog posts, pictures or other items. We want to create the text that should be displayed next to such an item.​Implement a function likes :: [String] -> String, which must take in input array, containing the names of people who like an item. It must return the display text as shown in t.. 2019. 3. 24.
[codewars] number fun NumberFun NumberFunxFYou might know some pretty large perfect squares. But what about the NEXT one?​Complete the findNextSquare method that finds the next integral perfect square after the one passed as a parameter. Recall that an integral perfect square is an integer n such that sqrt(n) is also an integer.​If the parameter is itself not a perfect square, than -1 should be returned. You may assu.. 2019. 3. 24.
[codewars] Dubstep dubstep DubstepxxxxxxxxxxFor example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".​Recently, Jonny has heard Polycarpus's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Polycarpus remixed. Help Jonny restore the original song.​InputThe input consist.. 2019. 3. 23.
[algorithm] 방 번호 방 번호x// 방 번호는 4자리// 숫자 세트는 0~9 숫자 하나씩이 한세트다.// 방 번호를 충족하기 위해서는 몇 세트가 필요한가?// * 6과 9는 호환 가능하다. (9999인 경우, '9' 2개와 '6' 2개를 사용해 2세트로 완성 가능하다.) 이번 문제는 스터디를하면서 풀게 된 문제이다.갑자기 풀게 된 문제라 그런지 인터넷에서 내가 문제를 골라서 풀 때랑은 아주 다른 느낌이었다.나는 단순한 사람이므로 그냥 문제 설명을 들은 대로 풀었다.숫자가 들어있는 세트를 가지고 숫자를 하나씩 꺼내 방 번호를 완성하는 식이었다. xxxxxxxxxximport java.util.Arrays;​class Solution { public static int solution(String room) { int resul.. 2019. 2. 22.
[programmers] K번째수 K번째수 K번째수x배열 array의 i번째 숫자부터 j번째 숫자까지 자르고 정렬했을 때, k번째에 있는 수를 구하려 합니다.​예를 들어 array가 [1, 5, 2, 6, 3, 7, 4], i = 2, j = 5, k = 3이라면1. array의 2번째부터 5번째까지 자르면 [5, 2, 6, 3]입니다.2. 1에서 나온 배열을 정렬하면 [2, 3, 5, 6]입니다.3. 2에서 나온 배열의 3번째 숫자는 5입니다.​배열 array, [i, j, k]를 원소로 가진 2차원 배열 commands가 매개변수로 주어질 때, commands의 모든 원소에 대해 앞서 설명한 연산을 적용했을 때 나온 결과를 배열에 담아 return 하도록 solution 함수를 작성해주세요. 와우네 문제 완전 귀찮네 했는데 나를 귀찮.. 2019. 1. 5.