1.两数之和(1)
https://leetcode-cn.com/problems/two-sum/
class Solution:
def twoSum(self, nums, target):
d = {}
for x in range(len(nums)):
if nums[x] in d:
return d[nums[x]],x
else:
d[target - nums[x]] = x
continue
2.Happy Number(202)
https://leetcode-cn.com/problems/happy-number/
class Solution(object):
def isHappy(self, n):
"""
:type n: int
:rtype: bool
"""
d = {}
while True:
l = list(map(int,list(str(n))))
m = 0
for i in l:
m += i**2
if m in d:
print(d)
return False
if m == 1:
print(d)
return True
d[m] = m
n = m