随笔分类 - leetcode
摘要:labuladong讲解 22. 括号生成(中等) 题目描述 给出n对括号,请编写一个函数来生成所有的由n对括号组成的合法组合。 例如,给出n=3,解集为: "((()))", "(()())", "(())()", "()(())", "()()()" Given n pairs of paren
阅读全文
摘要:题目描述 给出一个仅包含字符'(',')','{','}','['和']',的字符串,判断给出的字符串是否是合法的括号序列括号必须以正确的顺序关闭,"()"和"()[]{}"都是合法的括号序列,但"(]"和"([)]"不合法。 Given a string containing just the c
阅读全文
摘要:题目描述 给定一个链表,删除链表的倒数第n个节点并返回链表的头指针例如, 给出的链表为:1->2->3->4->5, n= 2.↵↵ 删除了链表的倒数第n个节点之后,链表变为1->2->3->5. 备注: 题目保证n一定是合法的请尝试只用一步操作完成该功能 Given a linked list,
阅读全文
摘要:题目描述 给出一个仅包含数字的字符串,给出所有可能的字母组合。 数字到字母的映射方式如下:(就像电话上数字和字母的映射一样) Input:Digit string "23"Output:["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]. 注
阅读全文
摘要:题目描述 给出一个有n个元素的数组S,S中是否有元素a,b,c和d满足a+b+c+d=目标值?找出数组S中所有满足条件的四元组。 注意: 四元组(a、b、c、d)中的元素必须按非降序排列。(即a≤b≤c≤d) 解集中不能包含重复的四元组。 例如:给出的数组 S = {1 0 -1 0 -2 2},
阅读全文
摘要:题目描述 给出含有n个整数的数组s,找出s中和加起来的和最接近给定的目标值的三个整数。返回这三个整数的和。你可以假设每个输入都只有唯一解。 例如,给定的整数 S = {-1 2 1 -4}, 目标值 = 1.↵↵ 最接近目标值的和为 2. (-1 + 2 + 1 = 2). Given an arr
阅读全文
摘要:15. 3Sum题目描述Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Exampl
阅读全文
摘要:题目描述: Given n non-negative integers a1 , a2 , ..., an , where each represents a point at coordinate (i, ai ). n vertical lines are drawn such that the
阅读全文
摘要:题目描述 给出一个整数数组,请在数组中找出两个加起来等于目标值的数, 你给出的函数twoSum 需要返回这两个数字的下标(index1,index2),需要满足 index1 小于index2.。注意:下标是从1开始的 假设给出的数组中只存在唯一解 例如: 给出的数组为 {2, 7, 11, 15}
阅读全文
摘要:题目一 permutations 题目描述 Given a collection of numbers, return all possible permutations. For example,[1,2,3]have the following permutations:[1,2,3],[1,3
阅读全文
摘要:You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, which
阅读全文
摘要:单链表的特点是:单向。设头结点位head,则最后一个节点的next指向NULL。如果只知道头结点head,请问怎么将该链表排序? 设结点结构为 struct Node{ int key; Node* next; }; 那么一般人见到这种题目,立马就会想到指针交换。是的,大家被指针交换的题目做多了,形
阅读全文
摘要:[LeetCode] Anagrams Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case. 思路: Anagrams指几个
阅读全文
摘要:题目描述 Implement pow(x, n). AC: class Solution { public: double pow(double x, int n) { if(x == 0 && n == 0) return 1; if(x == 0) return 0; if(n == 0) re
阅读全文
摘要:N-Queens The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, re
阅读全文
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array[−2,1,−3,4,−1,2,1
阅读全文
摘要:I: Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your ma
阅读全文
摘要:Given a collection of intervals, merge all overlapping intervals. For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18]. 合并有重叠的区间,且原区
阅读全文
摘要:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initia
阅读全文

浙公网安备 33010602011771号