摘要: 38. Count and Say The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 阅读全文
posted @ 2016-09-09 10:59 花椰菜菜菜菜 阅读(316) 评论(0) 推荐(0) 编辑
摘要: 36. Valid Sudoku Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cel 阅读全文
posted @ 2016-09-09 09:43 花椰菜菜菜菜 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 28. Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 子 阅读全文
posted @ 2016-09-07 21:38 花椰菜菜菜菜 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 27. Remove Element Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for 阅读全文
posted @ 2016-09-07 10:50 花椰菜菜菜菜 阅读(329) 评论(0) 推荐(0) 编辑
摘要: 26. Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that each element appear only once and return the ne 阅读全文
posted @ 2016-09-07 10:31 花椰菜菜菜菜 阅读(379) 评论(0) 推荐(0) 编辑
摘要: 链表操作的,要注意标记头结点和边界问题。 代码如下: 更加巧妙的解法,直接对链表中节点的val进行交换,不用操作链表; 代码如下: 阅读全文
posted @ 2016-09-06 22:08 花椰菜菜菜菜 阅读(283) 评论(0) 推荐(0) 编辑
摘要: 合并两个有序数列。属于基础的数据结构问题,核心在于对链表的操作。 代码如下: 阅读全文
posted @ 2016-09-06 16:08 花椰菜菜菜菜 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 判断括号的顺序是否正确; 思路:用一个堆栈来存储符号序列,按照符号匹配规则进行堆栈操作; 前括号一律入栈,后括号如果跟栈顶符号匹配,栈顶符号出栈如果,若不匹配则返回false; 最后栈为空返回true,否则返回false; 代码如下: 阅读全文
posted @ 2016-09-04 11:03 花椰菜菜菜菜 阅读(284) 评论(0) 推荐(0) 编辑
摘要: 最开始用一般的方法,首先遍历链表求出长度,进而求出需要删除节点的位置,最后进行节点的删除。 代码如下: 之后学习了别人更加巧妙的方法: 同时初始化两个指向头结点的指针,一个先向后走n步,然后两个指针同时向后移动, 当第一个指针到达终点的时候第二个指针的位置就是要删除的结点。 重写后提交竟然是100% 阅读全文
posted @ 2016-09-03 17:16 花椰菜菜菜菜 阅读(250) 评论(0) 推荐(0) 编辑
摘要: 14. Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings. 找出字符串集合的最长公共前缀。 思路:先计算出前两个字符串的最长公共前缀s 阅读全文
posted @ 2016-09-03 15:58 花椰菜菜菜菜 阅读(536) 评论(0) 推荐(0) 编辑