파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 6. 15. 23:45

https://leetcode.com/problems/longest-string-chain/

 

Longest String Chain - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

오늘도 시간이 없어서 ㅠㅠ

class Solution:
    def longestStrChain(self, words: List[str]) -> int:
        dp = {}
        res = 1
        for word in sorted(words, key=len):
            dp[word] = 1
            for i in range(len(word)):
                prev = word[:i] + word[i + 1 :]
                if prev in dp:
                    dp[word] = dp[prev] + 1
                    res = max(res, dp[word])

        return res
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.06.17
Today's Challenge  (0) 2022.06.16
Today's Challenge  (0) 2022.06.14
Today's Challenge  (0) 2022.06.13
Today's Challenge  (0) 2022.06.12
Comments