摘要: 解法一:水平扫描 int indexOf(String str): 在字符串中检索str,返回其第一出现的位置,如果找不到则返回-1 class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length 阅读全文
posted @ 2020-04-08 23:52 yawenw 阅读(544) 评论(0) 推荐(0) 编辑
摘要: 两种方法:时间复杂度都为O(N) 1.转为数组保存,求出总长度的一半 空间复杂度O(n) 2.快慢指针法,输出慢指针 空间复杂度O(1) JAVA class Solution { public ListNode middleNode(ListNode head) { ListNode[] res 阅读全文
posted @ 2020-04-08 15:51 yawenw 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 三种解法: 第一种是在数组中查找O(n^2) 第二种是在HashSet中查找O(n) 第三种是在有序数组中查找O(nlogn) JAVA class Solution { public int countElements(int[] arr) { int res = 0; for(int i = 0 阅读全文
posted @ 2020-04-08 11:58 yawenw 阅读(103) 评论(0) 推荐(0) 编辑