2013年7月7日
摘要: 题目: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.下面是一个数独的题目:其解:数独不是很了解,没做过。不过知道规则。就是在这个9x9的格纸中间添1到9的数字。使每一行不能重复,每一列也不能重复,然后上面那个粗线框起来的3x3的格纸中的数字也不能重复。不知道这样的游戏有啥意义。。 阅读全文
posted @ 2013-07-07 18:27 lichen782 阅读(698) 评论(0) 推荐(0) 编辑
摘要: 题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e.,0 1 2 4 5 6 7might become4 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 no duplicate exists in the array.就是说,排序数组可能是右移了一定位数。让你在这... 阅读全文
posted @ 2013-07-07 17:39 lichen782 阅读(2196) 评论(4) 推荐(0) 编辑
  2013年7月6日
摘要: 题目: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 length = 2. Another example is")()())", where the lon 阅读全文
posted @ 2013-07-06 20:38 lichen782 阅读(4426) 评论(1) 推荐(0) 编辑
摘要: 题目: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.For example, given:S:"barfoothefoobarman"L:["foo", &qu 阅读全文
posted @ 2013-07-06 11:29 lichen782 阅读(1866) 评论(1) 推荐(0) 编辑
  2013年7月5日
摘要: 题目:Given a linked list, reverse the nodes of a linked listkat a time and return its modified list. If the number of nodes is not a multiple ofkthen left-out nodes in the end should remain as it is. You may not alter the values in the nodes, only nodes itself may be changed. Only constant memory i... 阅读全文
posted @ 2013-07-05 17:04 lichen782 阅读(14059) 评论(1) 推荐(2) 编辑
  2013年7月4日
摘要: 题目:Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()"解法:leetcode上的解法很赞。 其实这也是利用的递归的分支。构建了一树状结构并遍历,叶子节点就是valid 阅读全文
posted @ 2013-07-04 17:56 lichen782 阅读(1089) 评论(0) 推荐(0) 编辑
摘要: 题目:Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5.就是让你删除单链表倒数第n个节点,同时希望能只遍历一次。解法一: 如果不遍历完所有节点,怎么知道倒数第n个在哪里呢? 阅读全文
posted @ 2013-07-04 15:50 lichen782 阅读(548) 评论(0) 推荐(0) 编辑
摘要: 题目:Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.For example, given array S = {-1 0 1 2 -1 -4}, A solution set is: (-1, 0, 1) (-1, -1, 2)额外的要求是不能返回重复的triplets,返回的a,b,c的顺序要是非递减的。解法一:首先想一下,三个数相加,要为0的话... 阅读全文
posted @ 2013-07-04 11:47 lichen782 阅读(1786) 评论(0) 推荐(0) 编辑
  2013年7月3日
摘要: 题目:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.就是说,x轴上 阅读全文
posted @ 2013-07-03 18:10 lichen782 阅读(5385) 评论(1) 推荐(1) 编辑
  2013年7月2日
摘要: 题目:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 刚开始的时候理解有误,以为是求中位数。其实不是。这里所谓的"median of the two sorted arrays"指的是:如果A.length + B.length 是奇数,返回merge后中间的那个数;如果是偶数,返回中间两个数的平均 阅读全文
posted @ 2013-07-02 15:31 lichen782 阅读(2498) 评论(0) 推荐(0) 编辑