![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
LeetCode
!
soulmate284
这个作者很懒,什么都没留下…
展开
-
力扣 删除排序链表中的重复元素
我的思路是:创建一个指针p用来移动比较,如果p.next的值==p.next.next的值,就删除下一个节点,即pre.next = pre.next.next,如果不同就移动下一个节点 public ListNode deleteDuplicates(ListNode head) { ListNode pre = head; ListNode next = head.next; if(head==null||head.next == null) { return head; }原创 2021-04-11 15:06:46 · 77 阅读 · 0 评论 -
力扣28实现 strStr() 函数
力扣28实现 strStr() 函数。 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。 public int strStr(String haystack, String needle) { //若needle为空,返回0 if(needle.length()==0) { System.out.println("needle为空"); retu原创 2021-04-08 10:19:42 · 119 阅读 · 0 评论 -
最长公共前缀
最长公共前缀 本来我的想法是先用第一个字符串比较,保留相同部分再比较,逐渐缩短,然后就写了这段又臭又长的代码,还不对…… /** * 0 <= strs.length <= 200 * 0 <= strs[i].length <= 200 * strs[i] 仅由小写英文字母组成 * @author soulmate * */ public class LongestCommonPrefix { public static String longestCommon原创 2021-04-07 15:23:17 · 77 阅读 · 0 评论