### 题意 Given two arrays, write a function to compute their intersection. 给定两个数组,写一个方法来计算它们的交集。 Example: ``` Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. ``` Note: - Each element in the result should appear as many times...
阅读全文>>2018年5月15日 10:29 作者:nancy 分类:[LeetCode] 1241
### 题意 Given two arrays, write a function to compute their intersection. 给定两个数组,写一个函数来计算它们的交集。 Example: ``` Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. ``` Note: - Each element in the result must be unique. - 每个在结果中的元素必定...
阅读全文>>2018年5月15日 09:28 作者:nancy 分类:[LeetCode] 1377
### 题意 Given a singly linked list, determine if it is a palindrome. 给定一个单链表,判断是否是“ 回文链表”。 Follow up: Could you do it in O(n) time and O(1) space? 你能在时间复杂度 O(n) 和空间复杂度 O(1) 下完成该问题吗? ### 思路 提取链表中的 val, 加入到 list 中,然后进行判断。 ```python ...
阅读全文>>2018年5月10日 20:32 作者:nancy 分类:[LeetCode] 1227
### 题意 Given a linked list, determine if it has a cycle in it. 给定一个链表,判断链表中是否有环。 Follow up: Can you solve it without using extra space? 你能否不使用额外空间解决此题? ### 思路 沿着链表不断遍历下去,如果遇到空节点就说明该链表不存在环。但如果存在环,这样的遍历就会进入死循环。在环上前进会不断地绕圈子,我们让两个速度不同...
阅读全文>>2018年5月6日 22:38 作者:nancy 分类:[LeetCode] 1314
### 题意 Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. 给定一个已按照升序排列的有序数组,找到两个数使得它们相加之和等于目标数。 The function twoSum should return indices of the two numbe...
阅读全文>>2018年5月4日 22:56 作者:nancy 分类:[LeetCode] 1270
### 题意 Write a function that takes a string as input and reverse only the vowels of a string. 编写一个函数,以字符串作为输入,反转该字符串中的元音字母。 ```python Example 1: Given s = "hello", return "holle". Example 2: Given s = "leetcode", return "leotcede". ```...
阅读全文>>2018年4月16日 23:23 作者:nancy 分类:[LeetCode] 1235
### 题意 Write a function that takes a string as input and returns the string reversed. 编写一个将字符串作为输入的函数,并返回反转的字符串。 ```python Example: Given s = "hello", return "olleh". ``` ### 思路 ```python class Solution(object): def reverseString(s...
阅读全文>>2018年4月15日 23:28 作者:nancy 分类:[LeetCode] 1383
### 题意 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。 Note: For the purpose of this problem, we define empty string as valid palindrome....
阅读全文>>2018年4月14日 21:16 作者:nancy 分类:[LeetCode] 1250
### 题意 Implement strStr(). 实现 strStr() 函数。 Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。...
阅读全文>>2018年4月9日 23:27 作者:nancy 分类:[LeetCode] 1214
### 题意 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. 给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组。 Note: The number of elements initialized in nums1 and nums2 are m and n re...
阅读全文>>2018年3月25日 20:35 作者:nancy 分类:[LeetCode] 1309
你还没有登录,请 或者