본문 바로가기

전체 글375

[Easy] LeetCode - no.290 Word Pattern : Java https://leetcode.com/problems/word-pattern/description/?envType=study-plan-v2&envId=top-interview-150  문제String pattern과 s가 서로 일대일 대응(bijection) 관계에 있는지 여부를 판단이 때 중복된 문자는 같은 단어에 대응해야 하고, 다른 문자는 다른 단어에 대응해야 함두 문자가 같은 단어에 대응하거나, 두 단어가 같은 문자에 대응하면 안 됨Example 1:Input: pattern = "abba", s = "dog cat cat dog"Output: trueExplanation:The bijection can be established as:'a' maps to "dog".'b' maps to "cat.. 2024. 10. 16.
[Easy] LeetCode - no.205 Isomorphic Strings : Java https://leetcode.com/problems/isomorphic-strings/description/?envType=study-plan-v2&envId=top-interview-150  문제String s와 t가 동형(isomorphic)인지 판별하는 문제이 때 두 문자열이 동형이라는 것은, 각 문자가 서로 일대일로 매핑되어야 하며, 동일한 문자가 다른 위치에서도 동일하게 매핑되어야 함을 의미함Example 1:Input: s = "egg", t = "add"Output: trueExplanation:The strings s and t can be made identical by:Mapping 'e' to 'a'.Mapping 'g' to 'd'.Example 2:Input: s = "foo",.. 2024. 10. 16.
[Easy] LeetCode - no.383 Ransom Note : Java https://leetcode.com/problems/ransom-note/description/?envType=study-plan-v2&envId=top-interview-150  문제magazine의 알파벳들로 ransomNote를 만들 수 있는지 여부를 판단하여 true 또는 false를 반환할 것이 때 magazine의 알파벳은 각각 한 번만 사용 가능Example 2:Input: ransomNote = "aa", magazine = "ab" Output: falseExample 3:Input: ransomNote = "aa", magazine = "aab" Output: true   풀이import java.util.*;class Solution { public boolean canCons.. 2024. 10. 14.
[Easy] LeetCode - no.392 Is Subsequence : Java https://leetcode.com/problems/is-subsequence/description/?envType=study-plan-v2&envId=top-interview-150  문제2개의 String 값인 s와 t가 주어졌을 때, s가 t의 subsequence라면 true를 반환, 아니라면 false를 반환할 것이 때  subsequence란 t의 순서를 유지하면서, 특정 문자를 지움으로써 s를 만들 수 있는지 여부이다.Example 1:Input: s = "abc", t = "ahbgdc" Output: trueExample 2:Input: s = "axc", t = "ahbgdc" Output: false   풀이class Solution { public boolean isSubse.. 2024. 10. 14.
[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.