码迷,mamicode.com
首页 >  
搜索关键字:return    ( 60766个结果
[LeetCode] Palindrome Partition [11]
题目:Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. 解题思路: 回文划分,题目意思是给一个字符串,找出将字符串划分为一系列回文子串的各种可能组合。例如,一个子串“aab“,你需要返回["aa","b"],["a","a","b"]。这个题目的解法也是非常的典型---循环加递归,...
分类:其他好文   时间:2014-06-09 23:24:11    阅读次数:256
leetcode——Two Sum 两数之和(AC)
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, whe...
分类:其他好文   时间:2014-06-09 23:14:45    阅读次数:264
LeetCode: Pascal's Triangle II [119]
【题目】 Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 【题意】 给定行索引k, k从0开始,返回该索引指向的杨辉三角的行 要求只能使用O(k)的额外空间 【思路】 ...
分类:其他好文   时间:2014-06-08 15:46:02    阅读次数:272
Unique Binary Search Trees II
题目 Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return all 5 unique BST's shown below. ...
分类:其他好文   时间:2014-06-08 15:15:26    阅读次数:223
leetcode——Reverse Words in a String 旋转字符串中单词顺序(AC)
题目如下: Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". click to show clarification. Clarification: What co...
分类:其他好文   时间:2014-06-08 14:58:13    阅读次数:231
[LeetCode] Reverse Integer [8]
题目 Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321。 解题思路: 颠倒一个整数中数字的位置,哈哈,类似翻转字符串一样,只不过整数需要计算,需要考虑溢出,其他无而。写出代码不难,只是溢出的时候怎么办,我这里是按照返回-1处理的,在leetcode上可以AC。 代码实现:...
分类:其他好文   时间:2014-06-08 14:47:58    阅读次数:257
Restore IP Addresses
题目 Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given "25525511135", return ["255.255.11.135", "255.255.111.3...
分类:其他好文   时间:2014-06-08 10:37:47    阅读次数:273
LeetCode: Pascal's Triangle [118]
【题目】 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 【题意】 给定整数numRows, 要求生成杨辉三角的前numRows行 【思路】 杨辉三角有以下特点: 1. 第n行有n个元素 ...
分类:其他好文   时间:2014-06-08 09:17:06    阅读次数:196
Interleaving String
题目 Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return true. When s3 = "aadb...
分类:其他好文   时间:2014-06-08 09:14:26    阅读次数:215
[LeetCode] ZigZag Conversion [9]
题目:convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR". 解题思路:这个是个纯粹找规律的题,其他没啥特殊的。下面的例子nRows=4; 找规律按照数组小标开始,寻找下标出现的规律, 1. 第一行和最后一行相邻元素下标之差为 2*nRows-2; 2. 除过第一行和最后一行,其余行要多一个元素,该元素出现的下标和行号有关,比如5 = 1 + 6 - 2,可以总结出规律为 j + 2*nRows-2 - 2*i; 关于 i 和 j 看以看下面...
分类:其他好文   时间:2014-06-08 09:11:57    阅读次数:230
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!