上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 16 下一页
摘要: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's undirected graph serialization: Nodes are labeled from 0 to N - 1, where N is the total nodes in the graph. We use # as a separator for each node, and , as a separator for each neighbor of the no 阅读全文
posted @ 2014-04-12 02:24 beehard 阅读(111) 评论(0) 推荐(0) 编辑
摘要: Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, given s = "catsanddog", dict = ["cat", "cats", "and", "sand", " 阅读全文
posted @ 2014-04-12 02:16 beehard 阅读(175) 评论(0) 推荐(0) 编辑
摘要: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s = "leetcode", dict = ["leet", "code"]. Return true because "leetcode" can be segmented as &qu 阅读全文
posted @ 2014-04-12 01:58 beehard 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 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] ] 1 class Solution { 2 public: 3 vector > generate(int numRows) { 4 vector > res(numRows); 5 for(int i = 0; i = 1) r... 阅读全文
posted @ 2014-04-12 01:40 beehard 阅读(102) 评论(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 @ 2014-04-11 10:30 beehard 阅读(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 @ 2014-04-11 09:10 beehard 阅读(383) 评论(0) 推荐(0) 编辑
摘要: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Note: A word is defined as a character sequence consists of non-space characters only. For example, Given s = " 阅读全文
posted @ 2014-04-11 04:54 beehard 阅读(139) 评论(0) 推荐(0) 编辑
摘要: Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n) space is pretty straight forward. Could you devise a constant space solution? Solution: 1. recursive solution. O(n) space. get inorder list first. ... 阅读全文
posted @ 2014-04-11 04:29 beehard 阅读(125) 评论(0) 推荐(0) 编辑
摘要: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time. Solution: Dynamic Programming. Space O(N). 1 class Solution { 2 public: 3 int ... 阅读全文
posted @ 2014-04-11 03:20 beehard 阅读(97) 评论(0) 推荐(0) 编辑
摘要: 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. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ ... 阅读全文
posted @ 2014-04-10 11:57 beehard 阅读(114) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 16 下一页