首页 > 编程语言 > 详细

Leetcode刷题记录[python]——349 Intersection of Two Arrays

时间:2016-05-19 19:06:52      阅读:254      评论:0      收藏:0      [点我收藏+]

一、前言

  做了两题才慢慢摸清了leetcode的操作。

 

二、题349 Intersection of Two Arrays

  Given two arrays, write a function to compute their intersection.

class Solution(object):
    def intersection(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: List[int]
        """
        nums3=[]
        nums4=[]
        i=0
        j=0
        for i in range(0, len(nums1)):
            if nums1[i] not in nums3:
                nums3.append(nums1[i])
        for j in range(0,len(nums2)):
            if nums2[j] in nums3 and nums2[j] not in nums4:
                nums4.append(nums2[j])
        return nums4

  其实前两题不难,思路也还比较清晰。

Leetcode刷题记录[python]——349 Intersection of Two Arrays

原文:http://www.cnblogs.com/Myoungs/p/5509635.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!