전체 글400 [Easy] LeetCode - no.28 Find the Index of the First Occurrence in a String : Java https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/description/?envType=study-plan-v2&envId=top-interview-150 문제needle이라는 단어가 haystack에 나타나지 않는다면 -1을 반환, 나타난다면 처음으로 나타나는 곳의 인덱스를 반환Example 1:Input: haystack = "sadbutsad", needle = "sad" Output: 0 Explanation: "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we return 0. 풀이class Solution { p.. 2024. 10. 13. [Easy] LeetCode - no.14 Longest Common Prefix ⭐ : Java https://leetcode.com/problems/longest-common-prefix/description/?envType=study-plan-v2&envId=top-interview-150 문제주어진 String 배열 strs의 공통된 prefix(접두어)를 구할 것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. 풀이 - 2가지 풀이 참고 (꼭 다시 풀어볼 것!)풀이1 public static String l.. 2024. 10. 13. [Easy] LeetCode - no.58 Length of Last Word : Java https://leetcode.com/problems/length-of-last-word/description/?envType=study-plan-v2&envId=top-interview-150 문제주어진 String s의 마지막 단어의 길이를 return할 것Example 2:Input: s = " fly me to the moon " Output: 4 Explanation: The last word is "moon" with length 4. 풀이class Solution { public int lengthOfLastWord(String s) { s = s.trim(); String[] str = s.split(" "); return str[str.le.. 2024. 10. 13. [Easy] LeetCode : no.13 Roman to Integer : Java https://leetcode.com/problems/roman-to-integer/description/?envType=study-plan-v2&envId=top-interview-150 문제로마 숫자를 int 값으로 바꾸어 반환할 것 주의할 점I can be placed before V (5) and X (10) to make 4 and 9. X can be placed before L (50) and C (100) to make 40 and 90. C can be placed before D (500) and M (1000) to make 400 and 900.Example 3:Input: s = "MCMXCIV" Output: 1994 Explanation: M = 1000, CM = 900, .. 2024. 10. 13. [Easy] LeetCode - no.121 Best Time to Buy and Sell Stock ⭐ : Java https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/?envType=study-plan-v2&envId=top-interview-150 문제주식을 구매할 날을 고르고, 미래의 다른 날에 팔았을 경우 얻을 수 있는 최대 수익을 반환할 것Example 1:Input: prices = [7,1,5,3,6,4] Output: 5 Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. Note that buying on day 2 and selling on day 1 is not allowed because you must buy b.. 2024. 10. 13. [Easy] LeetCode - no.169 Majority Element : Java https://leetcode.com/problems/majority-element/description/?envType=study-plan-v2&envId=top-interview-150 문제과반수를 차지하는 숫자를 return할 것(n / 2보다 많이 출현하는 숫자 찾기)Example 2:Input: nums = [2,2,1,1,1,2,2] Output: 2 풀이import java.util.*;import java.util.Map.*;class Solution { public int majorityElement(int[] nums) { int len = (nums.length % 2 == 0) ? nums.length / 2 : nums.length / 2 + 1; .. 2024. 10. 13. 이전 1 ··· 3 4 5 6 7 8 9 ··· 67 다음