标签归档:leetcode

RSS feed of leetcode

[LeetCode]Anagrams

题目描述:

Given an array of strings, return all groups of strings that are anagrams.

Note: All inputs will be in lower-case.

题目大意:

给定一个字符串数组,返回所有互为字谜(anagram,变位词)的字符串的分组。

注意:所有输入只包含小写字母

解题思路:

排序 + 哈希,使用Python的内置函数,例如reduce,filter等,可以简化代码。

解法I(字典+排序):

Python代码 ...

继续阅读

[LeetCode]Single Number

题目描述:

Given an array of integers, every element appears twice except for one. Find that single one.

Note:

Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

题目大意:

给定一个整数数组,除一个元素只出现一次外,其余各元素均出现两次。找出那个只出现一次的元素。

注意 ...

继续阅读

[LeetCode]Copy List with Random Pointer

题目描述:

A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.

Return a deep copy of the list.

题目大意:

给定一个链表,其中的节点包含一个额外的随机指针,可能指向链表中的任意一个节点或者为空。

返回链表的深拷贝。

解题思路:

解法I ...

继续阅读

[LeetCode]Different Ways to Add Parentheses

题目描述:

Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.

Example 1

Input: "2-1-1".

((2-1)-1) = 0
(2-(1-1 ...

继续阅读