HF_Cherish

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

随笔分类 -  Leetcode

摘要:1. Problem给定n对括号,生成所有可能的括号组合Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given ... 阅读全文
posted @ 2015-08-10 20:55 HF_Cherish 阅读(165) 评论(0) 推荐(0)

摘要:1. Problem一个字符串只能包含'(',')','{','}','['和']',判断字符串是否是闭合有效字符串。Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if... 阅读全文
posted @ 2015-07-22 21:58 HF_Cherish 阅读(160) 评论(0) 推荐(0)

摘要:1. Problem去掉链表的倒数第n个节点,并返回链表头。一次遍历完成Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list... 阅读全文
posted @ 2015-07-22 21:26 HF_Cherish 阅读(198) 评论(0) 推荐(0)

摘要:1. Question给定整型数组和target,找数组中的所有和为target的四个数,将其按值升序排列输出,输出结果不包含重复数对。Given an array S of n integers, are there elements a, b, c, and d in S such that a... 阅读全文
posted @ 2015-07-14 10:58 HF_Cherish 阅读(206) 评论(0) 推荐(0)

摘要:1. Question给一个数字字符串,按照电话上各个数字对应的字母,返回该字符串代表的所有可能的字母组合。Given a digit string, return all possible letter combinations that the number could represent.A ... 阅读全文
posted @ 2015-07-03 23:05 HF_Cherish 阅读(140) 评论(0) 推荐(0)

摘要:1. Question给定一个整型数组和key,找三个数,使其和与key最相近,返回这三个数的和。(假设至少会有一个解)Given an array S of n integers, find three integers in S such that the sum is closest to a... 阅读全文
posted @ 2015-06-29 11:02 HF_Cherish 阅读(161) 评论(0) 推荐(0)

摘要:1. Question将excel表中的列标题(A、B、C...)转换为对应的列数字返回。Given a column title as appear in an Excel sheet, return its corresponding column number.For example: ... 阅读全文
posted @ 2015-06-24 22:52 HF_Cherish 阅读(213) 评论(0) 推荐(0)

摘要:1. Question找数组中的大多数元素,即元素个数超过一般的那个元素Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ ... 阅读全文
posted @ 2015-06-24 22:48 HF_Cherish 阅读(198) 评论(0) 推荐(0)

摘要:1. Question判断一个树是否是平衡二叉树(每个节点的两个子树深度差不超过1)Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is d... 阅读全文
posted @ 2015-06-24 22:35 HF_Cherish 阅读(138) 评论(0) 推荐(0)

摘要:1. Question求二叉树的最大深度。Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node do... 阅读全文
posted @ 2015-06-24 22:12 HF_Cherish 阅读(144) 评论(0) 推荐(0)

摘要:1. Question判断一个二叉树是否是对称的。Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree i... 阅读全文
posted @ 2015-06-24 22:08 HF_Cherish 阅读(171) 评论(0) 推荐(0)

摘要:1. Question给定两个二叉树,判断是不是相同(结构相同,值相同)的树。Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equa... 阅读全文
posted @ 2015-06-24 22:00 HF_Cherish 阅读(149) 评论(0) 推荐(0)

摘要:1. Question给定有序链表,删除重复的,使每个元素仅出现一次。2. Solution(O(n))相似的有Remove Duplicates from Sorted Array,remove element/** * Definition for singly-linked list. * p... 阅读全文
posted @ 2015-06-24 21:55 HF_Cherish 阅读(163) 评论(0) 推荐(0)

摘要:1. Questionn级台阶,每次可以走一级或两级,问有多少种走法。You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In... 阅读全文
posted @ 2015-06-24 21:51 HF_Cherish 阅读(142) 评论(0) 推荐(0)

摘要:1. Question给定一个非负数,用数组存储其各数位,对这个数加一,返回结果。数组中,最高位在数组头。Given a non-negative number represented as an array of digits, plus one to the number.The digits ... 阅读全文
posted @ 2015-06-24 21:26 HF_Cherish 阅读(185) 评论(0) 推荐(0)

摘要:1. Question给定数组和一个值,去掉该数组中的这个值,返回新数组长度。要求操作是in place的,返回的数组元素位置可变,新数组之后的部分无所谓。Given an array and a value, remove all instances of that value in place ... 阅读全文
posted @ 2015-06-24 21:24 HF_Cherish 阅读(171) 评论(0) 推荐(0)

摘要:1. Question给定有序数组,去掉其中的重复元素,使得每个元素仅出现一次。要求实现是in place的,即仅能使用常数级的的额外空间。要求返回新数组的长度,同时原数组的该长度内是要求的数,该长度以后的数组内容无所谓。Given a sorted array, remove the duplic... 阅读全文
posted @ 2015-06-24 21:17 HF_Cherish 阅读(243) 评论(0) 推荐(0)

摘要:1. Question合并两个有序链表,返回的新链表是通过拼接原来的两个链表得到Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together th... 阅读全文
posted @ 2015-06-24 21:02 HF_Cherish 阅读(163) 评论(0) 推荐(0)

摘要:1. Question给一个整型数组,找所有唯一的和为0的三个数的数对。相似的题有2SumGiven an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique ... 阅读全文
posted @ 2015-06-24 11:28 HF_Cherish 阅读(237) 评论(0) 推荐(0)

摘要:1. Question找字符串数组的最长公共前缀,是所有字符串的。Write a function to find the longest common prefix string amongst an array of strings.2. Solution(O(mn))以第一个字符串作为前缀初值... 阅读全文
posted @ 2015-06-23 23:00 HF_Cherish 阅读(153) 评论(0) 推荐(0)