본문 바로가기

반응형

leetcode

(14)
[LeetCode] Valid Parentheses | 난이도: Easy 문제 Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. 예시 Input: s = "()" Output: true Input: s = "()[]{}" Output: true Input: s = "([)]" Output: false Input: s = "{[]}" Output: true 제약조건 1
[LeetCode] Longest Common Prefix | 난이도: Easy 문제 Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". 문자 배열에서 가장 긴 공통 접두사를 찾는 함수를 만드시오. 공통 접두사라 없을 시 ""를 리턴. 예시 Input: strs = ["flower","flow","flight"] Output: "fl" Input: strs = ["dog","racecar","car"] Output: "" Explanation: There is no common prefix among the input strings. 제약조건 1
[LeetCode] Roman to Integer | 난이도: Easy 문제 Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 로마자를 정수로 변환. 예시 Example 1 Input: s = "III" Output: 3 Example 2 Input: s = "IV" Output: 4 Example 3 Input: s = "IX" Output: 9 Example 4 Input: s = "LVIII" Output: 58 Explanation: L = 50, V= 5, III = 3. Example 5 Input: s = "MCMXCIV" Output: 1994 Explanation: M = ..
[LeetCode] Palindrome Number | 난이도: Easy 문제 Given an integer x, return true if x is palindrome integer. An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not. 주어진 정수 x의 값이 palindrome(회문(回文))일 경우 true를 리턴한다. *회문(回文) : madam이나 nurses run처럼 앞에서부터 읽으나 뒤에서부터 읽으나 동일한 단어나 구(출처: 네이버) 예시 Input: x = 121 Output: true 예시 Input: x = -121 Output: false Explanation: From left to right, ..
[LeetCode] Reverse Integer | 난이도: Easy 문제 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 [−2³¹, 2³¹ − 1], then return 0. 주어진 32비트 정수 x값이 있다. 정수 x 자릿수를 역으로 바꾸어라.만약 역으로 바꾼 정수의 값의 범위가 −2³¹, 2³¹ − 1를 넘어갔을 경우, 0을 반환한다. 예시 Input: x = 123 Output: 321 말 그대로 숫자를 반대로 뒤집는 것. 답안 class Solution { public int reverse(int x) { long res = 0; while(x != ..
[LeetCode] Two Sum | 난이도: Easy 문제 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이 있다. 정수 배열 nums의 인덱스 값의 합이 target과 동일한 경우 해당 인덱스 값을 리턴하시오. 예시 Input: nums = [2,7,11,15], target ..

반응형