摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *//** * Definition for binary tree * struc... 阅读全文
posted @ 2013-09-16 02:24 懒猫欣 阅读(160) 评论(0) 推荐(0)
摘要: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *mergeKLists(ve... 阅读全文
posted @ 2013-09-15 16:55 懒猫欣 阅读(141) 评论(0) 推荐(0)
摘要: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.class Solution {public: void merge(int A[], int m, int B[], int n) {... 阅读全文
posted @ 2013-09-15 15:54 懒猫欣 阅读(146) 评论(0) 推荐(0)
摘要: iven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11). Note: Bonus point i... 阅读全文
posted @ 2013-09-15 15:41 懒猫欣 阅读(191) 评论(0) 推荐(0)
摘要: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class So... 阅读全文
posted @ 2013-09-15 14:30 懒猫欣 阅读(148) 评论(0) 推荐(0)
摘要: 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 nu... 阅读全文
posted @ 2013-09-15 11:21 懒猫欣 阅读(371) 评论(0) 推荐(0)
摘要: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.简 阅读全文
posted @ 2013-09-15 01:47 懒猫欣 阅读(159) 评论(0) 推荐(0)
摘要: 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)