반응형

자바 119

[LeetCode] 12. Integer_to_Roman (JAVA)

문제 Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. 로마 숫자는 I, V, X, L, C, D 그리고 M의 7가지 기호로 표시됩니다. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two one's added together. 예를 들어, 2는 로마 숫자로 II로 표기되며, 일을 두번 더하면 됩니다. 12 is written as XII, which is simply X + II. 12는 XII로 표기되며, 단순히 X + II입니다. The number 27 is ..

[LeetCode] 11. Container With Most Water (Java)

문제 You are given an integer array height of length n. 길이가 n인 정수 배열 'height'가 제공됩니다. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). i번째 선의 두 끝점이 (i, 0) 및 (i, height[i])가 되도록 n개의 수직선이 그려집니다. Find two lines that together with the x-axis form a container, such that the container contains the most water. 컨테이너에 가장 많은 물이 포함되도록 컨테이너의 x축과 함께 형성..

[백준 Baekjoon] 10162번 전자레인지 - JAVA

문제풀이 최소버튼 동작을 구하기 위해서는 가장 가장 동작시간이 오래 걸리는 버튼을 최대로 누르면 됩니다. 가장 동작시간이 긴 A버튼 부터 남아있는 요리시간과 비교하여 버튼을 누를 수 있는 경우 해당 버튼을 누를 수 있는 최대를 구합니다. 시간을 정확히 맞출 수 없는 경우는 이 경우 버튼 C로 시간을 맞출 수 없는 경우입니다. 소스코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReade..

[백준 Baekjoon] 1268번 임시 반장 정하기 - JAVA

문제풀이 문제의 난이도는 브로즌 1이라지만, 체감은 더 난이도가 있었던것 같습니다. 풀기 엄청 귀찮은 문제였습니다. int[][] arr = new int[5][N]; Set[] dupCheckSet = new Set[N]; int max = 0, answer = 1; 표는 나중에 계산하기 편하게 i를 학년으로 j를 학생으로 생성하고 저장하였습니다. 중복되는 학생을 검사하기 위해 set 배열을 사용하였습니다. 한 번도 겹치지 않는 경우 1번 학생이 정답이여 초기값을 1로 하였습니다. for (int i = 0; i < 5; i++) { Map stuClsMap = new HashMap(); for (int j = 0; j < N; j++) { List value = stuClsMap.getOrDefaul..

[백준 Baekjoon] 2511번 카드놀이 - JAVA

문제풀이 간단한 구현문제입니다. A와 B의 카드를 문자열 배열로 저장합니다. 배열을 순회하며 A와 B의 카드를 비교합니다. 문자열의 기본 메소드 compareTo()를 사용하여, 문자열을 비교할 수 있습니다. 문자열을 비교하여 같은경우 0, 이외에는 A와 B 문자열의 차이를 리턴합니다. 마지막으로 이긴 사람을 저장합니다. 모든 라운드에서 비기는 경우는 초기화값인 'D'가 됩니다. A와 B의 최종 점수를 출력합니다. 이긴 사람을 출력합니다. 비기는 경우는 'D'를 출력합니다. 모든 라운드에서 비기는 경우인지 승자가 초기값인 'D'와 비교하여 검사합니다. 점수가 같은 경우 마지막으로 이긴 사람을 출력합니다. 점수가 다른 경우 더 높은 점수를 획득한 사람을 출력합니다. 소스코드 import java.io.Bu..

[LeetCode] 9. Palindrome Number (Java)

문제 Given an integer x, returntrue if x is palindrome integer. 정수 x가 주어지면, x가 회문 정수이면 true를 반환하세요. An integer is a palindrome when it reads the same backward as forward. 정수는 정방향과 역방향이 같을 때 회문입니다. For example, 121 is a palindrome while 123 is not. 예를 들어, 121은 회문이지만 123은 아닙니다. 회문이란? 회문(回文) 또는 팰린드롬(palindrome)은 거꾸로 읽어도 제대로 읽는 것과 같은 문장이나 낱말, 숫자, 문자열(sequence of characters) 등이다. 보통 낱말 사이에 있는 띄어쓰기나 문장 ..

[LeetCode] 8. String to Integer (atoi) (Java)

문제 Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function). 문자열을 32비트 부호 있는 정수로 변환하는 myAtoi(string s)함수를 구현합니다(C/C++의 atoi함수와 유사). The algorithm for myAtoi(string s) is as follows: myAtoi(string s)의 알고리즘은 다음과 같습니다: Read in and ignore any leading whitespace. 공백을 읽고 무시하세요. Check if the next character (if not already at the end ..

[LeetCode] 5. Longest Palindromic Substring (Java)

문제 Given a string s, return the longest palindromic substring in s. 문자열 s가 주어지면, s에서 가장 긴 회문(palindromic) 부분 문자열을 반환하세요. 회문이란? 회문(回文) 또는 팰린드롬(palindrome)은 거꾸로 읽어도 제대로 읽는 것과 같은 문장이나 낱말, 숫자, 문자열(sequence of characters) 등이다. 보통 낱말 사이에 있는 띄어쓰기나 문장 부호는 무시한다. 출처: 회문 - 위키백과 Example 1: Input: s = "babad" Output: "bab" Explanation: "aba" is also a valid answer.Example 2: Input: s = "cbbd" Output: "bb"제약 ..

[LeetCode] 4. Median of Two Sorted Arrays (Java)

문제 Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. 크기가 각각 m 및 n인 두 개의 정렬된 배열 nums1 및 num2가 주어질 때, 두 개의 정렬된 배열의 중간값을 반환합니다. The overall run time complexity should be O(log (m+n)). 전체 시간복잡도는 O(log(m+n))이어야 합니다. Example 1: Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Explanation: merged array = [1,2,3] and median is 2.Example 2:..

[LeetCode] 3. Longest Substring Without Repeating Characters (Java)

문제 Given a string s, find the length of the longest substring without repeating characters. 문자열 s가 주어지면, 반복되는 문자가 없는 가장 긴 부분 문자열의 길이를 찾으세요. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: s = "pwwkew" Output: 3 Explanation: The answer ..

반응형