반응형

leetcode 9

[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축과 함께 형성..

[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] 7. Reverse Integer (Java)

문제 Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0. 부호 있는 32비트 정수 x이 주어지면 숫자가 반전된 x를 반환합니다. x를 반전하면 값이 부호 있는 32비트 정수 범위 [-231, 231 - 1]를 벗어나면 0을 반환합니다. Assume the environment does not allow you to store 64-bit integers (signed or unsigned). 65비트 정수(부호가 있거나 없는)를 저장할 수 없..

[LeetCode] 6. Zigzag Converstion (Java)

문제 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) 문자열 "PAYPALISHIRING"은 다음과 같이 주어진 수의 행들에 지그재그 패턴으로 작성되어있습니다.(가독성을 높이기 위해 이 패턴을 고정 글꼴로 표시할 수 있습니다.) P A H N A P L S I I G Y I R And then read line by line: "PAYPALISHIRING" 그런 다음 한 줄씩 읽습니다: "PAYPALISHIRING" 문자열을 가져가고 주어진 수의 ..

[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 ..

반응형