摘要: Determine whether an integer is a palindrome. Do this without extra space. 1 public static bool PalindromeNumberRec(int x) 2 { 3 return isPalindrome(x, ref x); 4 } 5 6 public static bool isPalindrome(int x, ref int y) 7 { 8 if(x < 0) r... 阅读全文
posted @ 2012-10-02 22:45 ETCOW 阅读(300) 评论(0) 推荐(0) 编辑
摘要: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement must be in-place, do not allocate extra memory.He 阅读全文
posted @ 2012-10-02 05:42 ETCOW 阅读(659) 评论(0) 推荐(1) 编辑
摘要: Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions. 1 public static int NQueenII(int n) 2 { 3 int[] map = new int[n]; 4 int ret = NQueenIIHelper(map, n, 0); 5 return ret; 6 ... 阅读全文
posted @ 2012-10-02 03:40 ETCOW 阅读(231) 评论(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' 阅读全文
posted @ 2012-10-02 01:50 ETCOW 阅读(547) 评论(0) 推荐(0) 编辑