Algorithm/Leetcode (21) 썸네일형 리스트형 [Top Interview 150 - Hashmap] 290. Word Pattern [Q] [Easy]Given a pattern and a string s, find if s follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in s. Specifically:Each letter in pattern maps to exactly one unique word in s.Each unique word in s maps to exactly one letter in pattern.No two letters map to the same word, and no two words map to the same .. [Top Interview 150 - Hashmap] 205. Isomorphic Strings [Q] [Easy]Given two strings s and t, determine if they are isomorphic.Two strings s and t are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself. 길이 다르면 애초에 아니니까 따로 빼줬다.str.index() 함수 활용하여 index.. [Top Interview 150 - Hashmap] 383. Ransom Note [Q] [Easy]Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise.Each letter in magazine can only be used once in ransomNote. Hash 문제는 익숙해지는 것이 중요한 것 같다.dict.get() 만 알면 수월하게 풀 수 있었던 문제# Answerclass Solution: def canConstruct(self, ransomNote: str, magazine: str) -> bool: char_frequency = dict() .. [Top Interview 150 - Two Pointers] 167. Two Sum II - Input Array Is Sorted [Q] [Medium]Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 모르겠어서 찾아보고 풀음하나 고정해놓고 하나씩 더해보려고 헀는데, 왼쪽 / 오른쪽 하나씩 줄여나가는 방법이 더 좋다는 생각이 들었다.l 과 r 의 + / - 는 달라지면 안된다. -> sorted 되어 있기 때문에 # Answerclass Solution: def twoSu.. [Top Interview 150 - Two Pointers] 392. Is Subsequence [Q] [Easy]Given two strings s and t, return true if s is a subsequence of t, or false otherwise.A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not). 이런 문제가 취약점인가보다 좀 헷갈려서 찾아보고 풀었다. # Answ.. [Top Interview 150 - Two Pointers] 125. Valid Palindrome [Q] [Easy]A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.Given a string s, return true if it is a palindrome, or false otherwise. palindrome 이 뭔지 몰라서 처음부터 띠용했다.리스트 안의 문자열을 뒤집는 함수 [::-1] 만 알면 쉬운 문제! 까먹고 있어서 어렵게 돌아가다가 .. [Top Interview 150 - Array / String] 189. Rotate Array [Q] [Medium]Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.Constraints:1 일단 rotate 문제니까, deque.rotate(k) 쓰면 된다고 생각했다.그래서 작성했는데 먹히지 않음.이번엔 아래와 같이 작성했는데 또 안됨! 왜!조건들 때문이었다.. 그래서 if 문 추가하고 k가 n 보다 클 수 있어서 k%=n 추가하고 제출# Wrong Answerclass Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify num.. [Top Interview 150 - Array / String] 169. Majority Element [Q] [Easy]Given an array nums of size n, return the majority element.The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. 일단 in-place 문제가 아니면 좀 더 편하게 풀 수 있는 것 같다.라고 생각했는데 제출하니까 틀렸다고 한다.아무리봐도 틀린 부분이 없는 것 같아 colab 에서 돌려봤더니 맞게 답이 나오는데 어디서 연산이 잘못 되었을까..n 이 $len(nums)$ 라고 했는데 내가 다른 변수로 써서 그런가 해서 m 으로 바꿔보기도 하고, f.. 이전 1 2 3 다음