본문 바로가기

알고리즘과 자료구조

(5)
LeetCode 49. Group Anagrams Problem Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Constraints 1
LeetCode 819. Most Common Word(StringBuilder 이용) Problem: Given a string paragraph and a string array of the banned words banned, return the most frequent word that is not banned. It is guaranteed there is at least one word that is not banned, and that the answer is unique. Constraints: 1 0로 먼저 거른뒤에 하는 게 더 빠르다. Reference: https://leetcode.com/problems/most-common-word/discuss/1087237/Java-100-Faster-2ms
LeetCode 937. Reorder Data in Log Files(Lamda식을 이용한 sort) Problem identifier와 log를 포함한 문자열들 안에서 logs를 기준으로 정렬하는 문제였다. 처음에 identifier를 value로 하고 logs를 key로 한 HashMap을 이용해서 풀려고 했지만, log가 동일한 경우에 HashMap의 keySet(중복 허용x)의 문제 때문에 막혔다. 해쉬맵의 키가 Set이라는 것과 log가 같은 경우를 맞물려 생각 못 했다. class Solution { public String[] reorderLogFiles(String[] logs) { ArrayList l = new ArrayList();// letters ArrayList d = new ArrayList(); // digits String[] res = new String[logs.leng..
Leetcode 344. Reverse String Write a function that reverses a string. The input string is given as an array of characters s. - Constraints 1. 1
LeetCode 125. Valid Palindrome, java Given a string s, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. => palindrome : 뒤집어도 같은 말이 되는 단어나 문장 - Constraints : 1. 1='A'&&c1){ if(d.poll()!=d.pollLast()) return false; } return true; } } - 리스트의 remove(0)은 O(n), 데크의 poll()은 O(1) 3 ) 문자열에서 추출을 위해 정규표현식 이용 class Solution { public boolean isPalindrome(String s) { s = s.toLowerCase(); s = s.replace..