摘要: 题目: 实现 strStr() 函数。 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。 示例 1: 输入: haystack = "hello", needle = " 阅读全文
posted @ 2019-07-22 21:24 星辰大海。 阅读(394) 评论(0) 推荐(0) 编辑
摘要: 题意: 移除元素,移除数组nums中和val相同的元素,返回元素个数。 题解: 单独判断nums长度为0时的情况。然后构造for循环,将与val一样的剔除,保留不一样的。 代码: 阅读全文
posted @ 2019-05-12 22:24 星辰大海。 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 定义两个数,一个i用来遍历数组,一个sum用来记录不重复的数的个数。注意要将length=0和1的情况单独讨论。 阅读全文
posted @ 2019-05-03 20:44 星辰大海。 阅读(104) 评论(0) 推荐(1) 编辑
摘要: 要定义两个链表 判断时依次对应每一个链表的值进行判断即可。 阅读全文
posted @ 2019-04-28 23:03 星辰大海。 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 利用栈的操作,遇到"(","[","{"即进栈,遇到")","]","}"判断是否与栈顶匹配,若不匹配则false。 阅读全文
posted @ 2019-04-28 19:59 星辰大海。 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 最长公共前缀问题,考虑没有或只有一个字符串的情况,然后只需要逐个比对就可以了。 阅读全文
posted @ 2019-04-27 21:16 星辰大海。 阅读(211) 评论(0) 推荐(1) 编辑
摘要: 描述: Tram network in Zagreb consists of a number of intersections and rails connecting some of them. In every intersection there is a switch pointing t 阅读全文
posted @ 2019-03-04 23:27 星辰大海。 阅读(211) 评论(0) 推荐(0) 编辑
摘要: 描述: One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A t 阅读全文
posted @ 2019-03-03 17:37 星辰大海。 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 题意: Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. For example, two is written as II in Roman numeral, just two on 阅读全文
posted @ 2019-01-21 15:03 星辰大海。 阅读(246) 评论(0) 推荐(0) 编辑
摘要: 题意: 一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市。 Input前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第20行以后每行有1个数m,m<=20,m>=1.m=0退出. Output输出从第m个城市出发经过每 阅读全文
posted @ 2019-01-20 12:35 星辰大海。 阅读(103) 评论(0) 推荐(0) 编辑