Description
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
1 | [ |
Difficulty: Medium
Code:
1 | class Solution { |
题意
给定n对括弧,生成所有正确形式组合的字符串。
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
1 | [ |
Difficulty: Medium
Code:
1 | class Solution { |
给定n对括弧,生成所有正确形式组合的字符串。
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
Example:
1 | Input: 1->2->4, 1->3->4 |
Difficulty: Easy
Code:
1 | /** |
把K个有序链表合并成一个有序链表。
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]‘, determine if the input string is valid.
An input string is valid if:
Note that an empty string is also considered valid.
Example 1:
1 | Input: "()" |
Example 2:
1 | Input: "()[]{}" |
Example 3:
1 | Input: "(]" |
Example 4:
1 | Input: "([)]" |
Example 5:
1 | Input: "{[]}" |
Difficulty: Easy
Code:
1 | class Solution { |
给定一个字符串,只包含”(){}[]”,判断输入到字符串是否有效。开括号和必须以同样到类型到闭括号关闭,开括号必须以正确到顺序关闭。
Given a linked list, remove the n-th node from the end of list and return its head.
Example:
1 | Given linked list: 1->2->3->4->5, and n = 2. |
Note:
Given n will always be valid.
Follow up:
Could you do this in one pass?
Difficulty: Medium
Code:
1 | /** |
给定一个链表,移除链表的倒数第N个节点,并返回链表的头节点。限定N总是有效的不会超出链表长度,最好遍历一次。
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.
Note:
The solution set must not contain duplicate quadruplets.
Example:
1 | Given array nums = [1, 0, -1, 0, -2, 2], and target = 0. |
Difficulty: Medium
Code:
1 | class Solution { |
给定n个整数和一个目标整数,从n个整数中找出所有不重复的4个数字组合,使得它们之和等于目标整数。