摘要: Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.此题应用KMP算法来解,但忘记了,写了个普通解line 10: 当needle == "" 时, 返回haystackline 11: 循环终止条件需注意 1 public class Solution { 2 public static String strStr(String haystack, String needle) 阅读全文
posted @ 2013-07-24 10:17 feiling 阅读(198) 评论(0) 推荐(0) 编辑
摘要: Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.思路:两层循环,注意删除元素时指针要回溯,此方法的时间复杂度为O(n^2) 1 public class Solution { 2 public int removeElement(int[] A, int e 阅读全文
posted @ 2013-07-24 08:50 feiling 阅读(178) 评论(0) 推荐(0) 编辑