
LeetCode by Python
TtingZh
这个作者很懒,什么都没留下…
展开
-
1.Two Sum
思路:如果target与当前值的差值不在字典中,则将当前值与下标存放在字典里。 如果target与当前值的差值在HashMap中,则返回结果。 class Solution: def twoSum(self, nums, target): dict={} for i in range(len(nums)): x原创 2017-12-02 20:18:23 · 113 阅读 · 0 评论 -
2.add two sum
其实是模拟四则运算,刚开始很不明白关于ListNode 的问题#Definition for singly-linked list. #class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def ad原创 2017-12-02 20:50:07 · 167 阅读 · 0 评论 -
4. Median of Two Sorted Arrays
To solve this problem, we need to understand "What is the use of median". In statistics, the median is used for dividing a set into two equal length subsets, that one subset is always greater than th原创 2017-12-11 21:58:08 · 154 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
class Solution(object): def lengthOfLongestSubstring(self, s): dict={} res=0 start=0 for i,ch in enumerate(s): if ch in dict: res=max(re原创 2017-12-03 22:23:06 · 123 阅读 · 0 评论