摘要: http://oj.leetcode.com/problems/valid-sudoku/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.思路:按行,按列,再按3 * 3小方块检查,只要都通过就返回true,不然 阅读全文
posted @ 2013-11-01 13:12 移山测试工作室黑灯老师 阅读(2755) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/search-insert-position/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], 阅读全文
posted @ 2013-11-01 12:52 移山测试工作室黑灯老师 阅读(249) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/search-for-a-range/Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found in the array, return [-1, -1].For example,Given [5, 7 阅读全文
posted @ 2013-11-01 11:52 移山测试工作室黑灯老师 阅读(395) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/search-in-rotated-sorted-array/Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its index, otherwise return -1.You may assume 阅读全文
posted @ 2013-11-01 11:11 移山测试工作室黑灯老师 阅读(592) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/linked-list-cycle/Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?思路:这个问题是面试时很常见的问题,但是要求写代码的比较少。最简单的方法就是两个指针,一个每次走一步,一个每次走两步,等赶上了就说明有环。 1 class Solution { 2 public: 3 bool hasCycle(ListNode *head) { 4 ... 阅读全文
posted @ 2013-10-31 17:58 移山测试工作室黑灯老师 阅读(207) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/longest-valid-parentheses/Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", which has leng 阅读全文
posted @ 2013-10-31 17:34 移山测试工作室黑灯老师 阅读(371) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/next-permutation/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 阅读全文
posted @ 2013-10-30 21:34 移山测试工作室黑灯老师 阅读(527) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/substring-with-concatenation-of-all-words/You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening characters.F 阅读全文
posted @ 2013-10-30 17:53 移山测试工作室黑灯老师 阅读(6523) 评论(2) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/divide-two-integers/Divide two integers without using multiplication, division and mod operator.思路:典型的二分法。以87除4举例, (4 * 2 = 8) => (8 * 2 = 16) => (16 * 2 = 32) => (32 * 2) => 64,因为64 * 2 = 128大于87,现在我们可以确定4 * 16 = 64小于87,那么再处理87 - 64 = 23,23除4的话用上面方法可以得到5, 阅读全文
posted @ 2013-10-30 16:18 移山测试工作室黑灯老师 阅读(2313) 评论(1) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/implement-strstr/Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.思路:太简单了,没什么好说的。 1 class Solution { 2 public: 3 char *strStr(char *haystack, char *needle) { 4 int len_haystack = strlen(haystack), l... 阅读全文
posted @ 2013-10-30 15:11 移山测试工作室黑灯老师 阅读(560) 评论(0) 推荐(0) 编辑
count website visits
Buy Computers