摘要: Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.通过动归,每次i,j终点的串是回文需要s[i]==s[j]且i+1,j-1串是回文class Solution {public: string longestPalindrome(string s) { // Start typin... 阅读全文
posted @ 2013-09-14 22:38 懒猫欣 阅读(173) 评论(0) 推荐(0)
摘要: You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up: Could you do this in-place?class Solution {public: void rotate(vector > &matrix) { // Start typing your C/C++ solution below // DO NOT write int main() function int n=... 阅读全文
posted @ 2013-09-14 01:18 懒猫欣 阅读(122) 评论(0) 推荐(0)
摘要: 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, return all distinct solutions to the n-queens puzzle.Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and & 阅读全文
posted @ 2013-09-14 00:28 懒猫欣 阅读(192) 评论(0) 推荐(0)