Sandbox

  • 홈
  • 태그
  • 방명록

string 3

[LeetCode] Group Anagrams

Problem Solution Two strings are anagrams if the frequencies of appearing alphabets are the same. Make a dictionary, where the keys are tuples of alphabet(a-z) frequencies. The values are the strings in the given list. When I initiated an dictionary and used append function with a new key, it gave a KeyError. To avoid this, use defaultdict function and pass list as parameter. Then a defaultdict ..

CODE/Algorithms & Data Structures 2021.10.13

[LeetCode] Longest Palindromic Substring

Problem Solution Start from the center of the string, and expand to left and right until the characters at those positions are not the same. class Solution(object): def longestPalindrome(self, s): """ :type s: str :rtype: str """ if s is None or len(s) < 1: return "" start = 0 end = 0 for i in range(len(s)): len1 = self.expandCenter(s, i, i) len2 = self.expandCenter(s, i, i+1) length = max(len1,..

CODE/Algorithms & Data Structures 2021.10.11

[LeetCode] Minimum Deletions to Make Character Frequencies Unique

Problem Solution Make a dictionary of all appearing alphabets and their frequencies. Make a set of unique frequencies. Go through the dictionary and check if the frequency for this character already exists in the set. If it is, decrement the frequency until it is unique or reaches zero. Increment the counter at the same time. Add the frequency to the set. My code exceeded the time limit at first..

CODE/Algorithms & Data Structures 2021.10.03
이전
1
다음
더보기
프로필사진

Sandbox

  • 분류 전체보기 (48)
    • CODE (2)
      • Algorithms & Data Structure.. (43)
      • React (0)
    • READ (3)

Tag

binary search tree, depth first search, LeetCode, Merge Sort, LinkedList, hackerrank, array, java, algorithm, preorder traversal, Binary Search, Binary Tree, Coderust, level order traversal, inorder traversal, dynamic programming, Linked List, python3, Implementation, string,

최근글과 인기글

  • 최근글
  • 인기글

최근댓글

공지사항

페이스북 트위터 플러그인

  • Facebook
  • Twitter

Archives

Calendar

«   2025/05   »
일 월 화 수 목 금 토
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

방문자수Total

  • Today :
  • Yesterday :

Copyright © Kakao Corp. All rights reserved.

티스토리툴바