摘要: The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"one 2, thenone 1"or1211.Given an integern, generate thenthsequence.Note: The sequence of inte 阅读全文
posted @ 2013-08-02 23:56 feiling 阅读(428) 评论(0) 推荐(0) 编辑
摘要: Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character'.'.You may assume that there will be only one unique solution.A sudoku puzzle...思路:回溯(Backtracking),回溯题练得太少,知道应该用回溯写,但不知如何下笔。。。。。下面代码是参考网上博客写的,回溯题有如下几点需要注意:1. 应当有个独立的isValid判断函数2. 递 阅读全文
posted @ 2013-08-02 22:59 feiling 阅读(419) 评论(0) 推荐(0) 编辑
摘要: Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character'.'.A partially filled sudoku which is valid.判断数独是否合法:1. 同一行中1-9出现次数不重复2. 同一列中1-9出现次数不重复3. 9宫格中1-9出现次数不重复这里将1,2的判断在一个循环体中进行,分开进行跑 阅读全文
posted @ 2013-08-02 15:23 feiling 阅读(252) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here are few examples.[1,3,5,6], 5 → 2[1,3,5,6], 2 → 1[1,3,5,6], 7 → 4[1,3,5,6], 0 → 0思路:二分搜索,如search到则返 阅读全文
posted @ 2013-08-02 13:18 feiling 阅读(307) 评论(0) 推荐(0) 编辑