049 Group Anagrams


Problem

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

Test

1
2
3
4
5
Input: "babad"

Output: "bab"

Note: "aba" is also a valid answer.
1
2
3
Input: "cbbd"

Output: "bb"

Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!python3


class Solution:
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
dic = {}
for index, num in enumerate(nums):
if num in dic:
return [dic[num], index]
dic[target - num] = index


if __name__ == "__main__":
nums = [2, 7, 11, 15]
target = 9
assert (Solution().twoSum(nums, target) == [0, 1])
nums = [3, 2, 4]
target = 6
assert (Solution().twoSum(nums, target) == [1, 2])

$\alpha=\beta$