摘要: 题目描述: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close i 阅读全文
posted @ 2016-07-05 00:26 godlei 阅读(329) 评论(0) 推荐(0)
摘要: 题目描述: Given a linked list, remove the nth node from the end of list and return its head. 解题分析: 这个题的关键是找到倒数第n个节点:设置两个标记变量,想让其中1个走n-1步,然后两个一起往后走,当第一个变量指 阅读全文
posted @ 2016-07-05 00:24 godlei 阅读(196) 评论(0) 推荐(0)
摘要: 题目描述: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the arra 阅读全文
posted @ 2016-07-05 00:22 godlei 阅读(181) 评论(0) 推荐(0)
摘要: 题目描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. 解题分析: 这种类型的题必然要用位运算,虽然自己写了关于位运算的代码,但是不够简洁。 后来参考了 阅读全文
posted @ 2016-07-05 00:19 godlei 阅读(244) 评论(0) 推荐(0)
摘要: 题目描述: Given a digit string, return all possible letter combinations that the number could represent. 解题分析: 回溯法的典型应用,用一个数据结构表示出按键与其表示字母的对应关系,直接用回溯法做即可。 阅读全文
posted @ 2016-07-05 00:17 godlei 阅读(161) 评论(0) 推荐(0)
摘要: 题目描述: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three int 阅读全文
posted @ 2016-07-03 03:06 godlei 阅读(180) 评论(0) 推荐(0)
摘要: 题目描述: Given a roman numeral, convert it to an integer. 解题分析: 这道题只要百度一下转换的规则,然后着这解释写代码即可。实现上并没有什么难度,直接看代码即可 具体代码: 阅读全文
posted @ 2016-07-03 02:52 godlei 阅读(166) 评论(0) 推荐(0)
摘要: 题目描述: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the s 阅读全文
posted @ 2016-07-03 02:44 godlei 阅读(178) 评论(0) 推荐(0)
摘要: 题目描述: Write a function to find the longest common prefix string amongst an array of strings. 解题思路: 这道题很简单,分两步: 1. 找出所有字符串中长度最小的那个字符串的值(可能的结果的最大值,保证查找时 阅读全文
posted @ 2016-07-03 02:28 godlei 阅读(221) 评论(0) 推荐(0)
摘要: 题目描述: Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 阅读全文
posted @ 2016-06-28 00:24 godlei 阅读(1926) 评论(1) 推荐(0)