본문 바로가기

leetcode13

[LeetCode] Length of Last Word (javascript) 문제 Given a string s consisting of some words separated by some number of spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only. 문제[번역] 공백이 포함된 문자열 s가 주어집니다. 주어진 문자열에서 마지막 단어의 길이를 출력하세요. Example 1: Input: s = "Hello World" Output: 5 Explanation: The last word is "World" with length 5. Example 2: Input: s = " fly me to the m.. 2022. 4. 11.
[LeetCode] Maximum Subarray (javascript) 문제 Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. A subarray is a contiguous part of an array. 문제[번역] 정수 숫자열이 주어집니다. 최소 하나의 숫자를 포함한 연속적 최대 합을 구하세요 Example 1 Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. Example 2 Input: nums = [1] Output: 1 Example 3 Input:.. 2022. 3. 7.
[LeetCode] Search Insert Position (javascript) 문제 Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. 문제[번역] 정렬된 숫자 와 타겟 숫자가 주어집니다. 타겟을 찾으면 해당 인덱스를 리턴하고, 못찾으면, 순서에 맞는 인덱스를 리턴하세요. O(log n) 알고리즘을 써야합니다. Example 1 Input: nums = [1,3,5,6], target = 5 Output: 2 Ex.. 2022. 2. 15.
[LeetCode] Valid Parentheses (javascript) 문제 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. 문제[번역] '(', ')', '{', '}', '[' ,']'를 포함한 문자열이 주어집니다. 문자열이 유효한지 평가하세요. 1. 열린괄호는 같은괄호로 닫혀야함. 2. 열린 괄호는 순서대로 닫혀야함. Example 1 Input: s = "(.. 2021. 12. 27.
[LeetCode] Roman to Integer (Javascript) 문제 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 For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II. Roman numerals are usually written largest to smallest from left to right. How.. 2021. 12. 17.
[LeetCode] palindrome (javascript) 문제 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를 리턴합니다. palindrome 정수란, 뒤로 읽어도 같은 수를 의미합니다. 예를 들면 121은 palindrome이며, 123은 아닙니다. Example 1 Input: x = 121 Output: true Example 2 Input: x = -121 Output: false Explanation: Fro.. 2021. 12. 16.
반응형