python-algorithm
leetcode 2744. Find Maximum Number of String Pairs
무적김두칠
2023. 7. 13. 18:20
https://leetcode.com/problems/find-maximum-number-of-string-pairs/description/
Find Maximum Number of String Pairs - LeetCode
Can you solve this real interview question? Find Maximum Number of String Pairs - You are given a 0-indexed array words consisting of distinct strings. The string words[i] can be paired with the string words[j] if: * The string words[i] is equal to the rev
leetcode.com
1
2
3
4
5
6
7
8
9
10
|
class Solution:
def maximumNumberOfStringPairs(self, words: List[str]) -> int:
answer = 0
for i in range(len(words)):
for j in range(i+1, len(words)):
if sorted(words[i]) == sorted(words[j]):
answer += 1
break
return answer
|
cs |
반응형