[LeetCode]Gray Code
摘要:题目:Gray Code 给定格雷码的位数,输出所有的格雷码对应的十进制数。 思路: 000 0 001 1 011 3 010 2 110 6 111 7 101 5 100 4 前四个和后四个的前两位对称,前两个和后两个的第一位是对称的。 如此,可看出,格雷码有一定的对称性。
阅读全文
[LeetCode]Longest Increasing Path in a Matrix
摘要:题目:Longest Increasing Path in a Matrix Given an integer matrix, find the length of the longest increasing path. From each cell, you can either move to
阅读全文
[LeetCode]Word Search
摘要:题目:Word Search 判断某一单词是否在一个字母数组中用一条折线连起来。 word = "ABCCED", -> returns true, 坐标序列如下:00,01,02,12,22,21 思路: 递归查找单词当前字母对应数组的坐标的前后左右,看能都匹配。
阅读全文
[LeetCode]Longest Palindromic Substring
摘要:题目:Longest Palindromic Substring 查找最长回文子串 思路: 一个指针从头部,一个指针从尾部,对比每一个字母,若相等则可能是回文子串,则,检测子串是否回文,是则比较和已知的子串长度,更长就记录其起始和终止坐标,否则就放弃。 上面的思路是从两边向中间收束,另一个思路是从中
阅读全文
[LeetCode]Letter Combinations of a Phone Number
摘要:题目:Letter Combinations of a Phone Number 将电话号码的组合转换称所有可能的字母组合。 思路: 首先将电话键盘中的0->9的数字对应的字母集合放到一个常量二维数组中便于搜索。 [ [' ']//0 []//1 ['a','b','c']//2 ... ['w',
阅读全文
[LeetCode]Generate Parentheses
摘要:题目:Generate Parentheses 要找到所有可能的括号配对情况。 思路: 递归求解,记录当前已添加到字符串中的左括号个数, 每次判断当前是否可用左括号和右括号,都可以则将现有的字符串复制一份,表示增加一种情况。 当左括号已用完,则只能添加右括号。 当所有左括号都已配对且还有剩余括号时,
阅读全文
[LeetCode]sum合集
摘要:LeetCode很喜欢sum,里面sum题一堆。 1.Two Sum Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may a
阅读全文