본문 바로가기

알고리즘/LeetCode14

[LeetCode] 016. 3Sum Closest JAVA 3Sum Closest - LeetCode 3Sum Closest - Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution. Examp leetcode.com 📍 문제 Given an integer array nums of length n and an integer target, find three integers in nums such that t.. 2023. 1. 5.
[LeetCode] 015. 3Sum JAVA 📍 문제 Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. 정수 배열 nums가 주어지면 i != j, i != k, j != k nums[i] + nums[j] + nums[k] == 0. 조금 더 설명을 하자면, 정수 배열인 nums가 주어지면 인덱스가 다른 세 수의 합이 0이 되면 해당 숫자들을 리스트에 담고 그 리스트를 다시 리스트에 담아서 리턴시키면 되.. 2023. 1. 5.
[LeetCode] 014.Longest Common Prefix JAVA Longest Common Prefix - LeetCode 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: st leetcode.com ❄️ 문제 Write a function to find the longest common prefix string amongst an array of strings. If th.. 2023. 1. 4.
[LeetCode] 013. Roman to Integer JAVA https://leetcode.com/problems/roman-to-integer/ ☀️ 문제 Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. For 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. Roman numerals are usually written largest to smallest from left to right. How.. 2022. 12. 30.
[LeetCode] 011.Container With Most Water JAVA ☃️ 문제 You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not slant the container. 길이가 n인 정수 배열 높이가 주.. 2022. 12. 26.
[LeetCode] 012. Integer to Roman JAVA Integer to Roman - LeetCode Integer to Roman - 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 XI leetcode.com 🎄 문제 Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. For example, 2 i.. 2022. 12. 23.
[LeetCode] 004. Median of Two Sorted Arrays JAVA Median of Two Sorted Arrays - LeetCode Median of Two Sorted Arrays - Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: Input: nums1 = [1,3], nums2 = [2] Output: leetcode.com 📍문제 ENG Given two sorted arrays nums1 and nums2 of size m and n respectively, return the medi.. 2022. 12. 22.
[LeetCode] 008. String to Integer (atoi) JAVA String to Integer (atoi) - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 📍 문제 ENG Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function). The algorithm for myAtoi(string s) is as follows: 1️⃣ Read in and igno.. 2022. 12. 21.
[LeetCode]006. Zigzag Conversion JAVA Zigzag Conversion - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 📌 문제 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) P A H N A P L S I I G Y I R And then.. 2022. 12. 21.
[LeetCode]007. Reverse Integer JAVA Reverse Integer - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 📌 문제 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. Assume the environment does not a.. 2022. 12. 19.
[LeetCode]005. Longest Palindromic Substring JAVA Longest Palindromic Substring - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 📌 문제 Given a string s, return the longest palindromic substring in s. 📌 방법 반복문을 통해 문자열의 길이만큼 반복 그 안에서 반복되는 문자열 중 가장 긴 문자열을 출력 팰린드롬은 거꾸로 읽어도 제대로 읽는 것과 같은 낱말, 숫자, 문자열 따라서 반으로 접었을 때에, 양 옆이 같음. 때문에 반복문을 통해 .. 2022. 12. 19.
[LeetCode] 003. Longest Substring Without Repeating Characters JAVA Longest Substring Without Repeating Characters - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 📌 문제 Given a string s, find the length of the longest substring without repeating characters. 📌 방법 컬렉션을 이용하여 풀이 그 중에서 Set의 HashSet을 이용하여 풀이 1️⃣ 최댓값 max 선언 및 초기화 2️⃣ HashSet을 이용하여 풀이 3️⃣.. 2022. 12. 16.