摘要: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama"is a palindrome."race a car"isnota palindrome.Note:Have you consider that the string might be empty? This is a good question to 阅读全文
posted @ 2013-08-07 23:25 feiling 阅读(218) 评论(0) 推荐(0) 编辑
摘要: Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]]java 中是传值的,将count作为返回值返回 1 public static int[][] generateMatrix(int n) { 2 // Start typing your Java... 阅读全文
posted @ 2013-08-07 22:33 feiling 阅读(326) 评论(0) 推荐(0) 编辑
摘要: Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You should return[1,2,3,6,9,8,7,4,5]. 1 public class Solution { 2 public ArrayList spiralOrder(int[][] matrix) { 3 ... 阅读全文
posted @ 2013-08-07 22:15 feiling 阅读(309) 评论(0) 推荐(0) 编辑
摘要: C++中#include包含头文件带 .h 和不带 .h 的区别?如 #include 和 #include 包含的东西有哪些不同?之前在写C++程序的时候只知道使用 #include 的时候,使用函数前要用 using namespace std; 导入命名空间,而 #include 则不用,这个得看C++标准化过程为C++开发者做了哪些有意义的工作。(1)C++增加了名称空间概念,借以将原来声明在全局空间下的标识符声明在了namespace std下。(2)统一C++各种后缀名,如.h、.hpp、.hxx等。标准化之前的头文件就是带后缀名的文件,标准化后的头文件就是不带后缀名的文件... 阅读全文
posted @ 2013-08-07 20:51 feiling 阅读(1508) 评论(0) 推荐(1) 编辑
摘要: Implement pow(x,n).直接计算会超时TLE 1 public double pow(double x, int n) { 2 // Start typing your Java solution below 3 // DO NOT write main() function 4 if(n == 0) 5 return 1; 6 7 double result = 1; 8 if(n > 0){ 9 while(n > 0){10 ... 阅读全文
posted @ 2013-08-07 20:02 feiling 阅读(323) 评论(0) 推荐(0) 编辑
摘要: Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.Input: ["tea","and","ate","eat","den"]Output:["tea","ate","eat"]["",""]-------------> 阅读全文
posted @ 2013-08-07 15:00 feiling 阅读(1391) 评论(1) 推荐(0) 编辑
摘要: You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?如下图,首先沿逆对角线翻转一次,然后按x轴中线翻转一次。 1 public void rotate(int[][] matrix) { 2 // Start typing your Java solution below 3 // DO NOT write main() function 4 ... 阅读全文
posted @ 2013-08-07 13:27 feiling 阅读(231) 评论(0) 推荐(0) 编辑
摘要: Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2]have the following unique permutations:[1,1,2],[1,2,1], and[2,1,1].解题思路:Permutations 那题输入是不包含重复元素的,故生成的排列都是不同的,II中输入元素可能相同因而可能会产生相同的排列,这里需要去重,没有找到很好的剪枝条件,这里使用HashSet来去重,当发现已经添加过该组合 阅读全文
posted @ 2013-08-07 10:49 feiling 阅读(382) 评论(0) 推荐(0) 编辑
摘要: Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], and[3,2,1].求每个位置所有可能出现的情况:固定第一个字符,然后求后面所有字符的排列。这个时候仍把后面的所有字符分成两部分:后面字符的第一个字符,以及这个字符之后的所有字符 1 public class Solution { 2 public ArrayList> per. 阅读全文
posted @ 2013-08-07 09:58 feiling 阅读(291) 评论(0) 推荐(0) 编辑