파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 5. 29. 23:45

https://leetcode.com/problems/maximum-product-of-word-lengths/

 

Maximum Product of Word Lengths - 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

n이 그렇게 크지 않아서, 그냥 문제가 원하는대로 풀면 됨.

class Solution:
    def maxProduct(self, words: List[str]) -> int:
        res = 0
        l = len(words)
        word = [set(x) for x in words]
        for i in range(l-1):
            for j in range(i+1, l):
                if not word[i] & word[j]:
                    temp = len(words[i]) * len(words[j])
                    if res < temp:
                        res = temp
        return res
반응형

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

Today's Challenge  (0) 2022.05.31
Today's Challenge  (0) 2022.05.30
Today's Challenge  (0) 2022.05.28
Today's Challenge  (0) 2022.05.27
Today's Challenge  (0) 2022.05.26
Comments