본문 바로가기

JAVA/Coding Test Study151

[Easy] LeetCode - no.125 Valid Palindrome : Java https://leetcode.com/problems/valid-palindrome/description/?envType=study-plan-v2&envId=top-interview-150  문제주어진 String 값의 영어, 숫자만을 추려 소문자로 변환하였을 때 앞으로 읽거나 뒤로 읽거나 같은 경우(palindrome)일 경우 true 반환, 아니면 false 반환Example 1:Input: s = "A man, a plan, a canal: Panama" Output: true Explanation: "amanaplanacanalpanama" is a palindrome.   풀이class Solution { public boolean isPalindrome(String s) { .. 2024. 10. 13.
[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.