摘要: 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) 编辑