본문 바로가기

전체 글60

[리트코드][LeetCode][Easy][JAVA]35. Search Insert Position 문제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. Example 1:Input: nums = [1,3,5,6], target = 5Output: 2Example 2:Input: nums = [1,3,5,6], target = 2Output: 1Example 3:Input: nums = [1,3,5,6], target = 7Output.. 2024. 9. 21.
[리트코드LeetCode][Easy][JAVA]58. Length of Last Word 문제Given a string s consisting of words and spaces, return the length of the last word in the string.A word is a maximal substring consisting of non-space characters only. Example 1:Input: s = "Hello World"Output: 5Explanation: The last word is "World" with length 5.Example 2:Input: s = " fly me to the moon "Output: 4Explanation: The last word is "moon" with length 4.Example 3:Input: s = ".. 2024. 9. 21.
[리트코드LeetCode][Easy][JAVA]21. Merge Two Sorted Lists 문제You are given the heads of two sorted linked lists list1 and list2.Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists.Return the head of the merged linked list. Example 1:Input: list1 = [1,2,4], list2 = [1,3,4]Output: [1,1,2,3,4,4]Example 2:Input: list1 = [], list2 = []Output: []Example 3:Input: list1 = [], list2 = [0]Output:.. 2024. 9. 16.
[리트코드LeetCode][Easy][JAVA]20. Valid Parentheses 문제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.Every close bracket has a corresponding open bracket of the same type. Example 1:Input: s = "()"Output: trueExample 2:Input: s = "()[]{}"Out.. 2024. 9. 15.
[리트코드LeetCode][Easy][JAVA][JavaScript]14. Longest Common Prefix 문제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 "". Example 1:Input: strs = ["flower","flow","flight"]Output: "fl"Example 2:Input: strs = ["dog","racecar","car"]Output: ""Explanation: There is no common prefix among the input strings. Constraints:1 0 strs[i] consists of only lowercase English letters.   .. 2024. 9. 14.
[리트코드LeetCode][Easy][JAVA]13. Roman to Integer 문제Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D 500M 1000For example, 2 is written as II in Roman numeral, just two ones added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II... 2024. 9. 13.