方法1:迭代 m、n为两个有序链表的长度 时间复杂度:O(m+n) 空间复杂度:O(1) class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next class Solution: def ...
分类:
其他好文 时间:
2020-06-25 09:54:49
阅读次数:
43
方法一: 哈希表 时间复杂度:O(n) 空间复杂度:O(n) class Solution: def hasCycle(self, head: ListNode) -> bool: dict = {} while head: if head in dict: return True else: di ...
分类:
其他好文 时间:
2020-06-25 09:26:14
阅读次数:
60
在服务器上安装xxx软件时报错,提示如下: Installation failed with error code: (0x80070643), "Fatal error during installation...". Solution: 1. 将当前登录帐号登录到Local Administra ...
分类:
其他好文 时间:
2020-06-25 09:23:11
阅读次数:
125
啊,是较简单的一题呢。有一些操作再熟悉一下。 思路就是建立一个HashMap用于计数,然后再遍历就行。时间空间复杂度都是ON 自己写的代码如下: class Solution { public int firstUniqChar(String s) { HashMap<Character,Integ ...
分类:
其他好文 时间:
2020-06-24 23:55:48
阅读次数:
113
题目 1436. 旅行终点站 思路分析 这个题其实很简单啊,可以把它看成一个有向图,我们需要在这个有向图中找出度为0的点即可。 代码实现 class Solution { public String destCity(List<List<String>> paths) { HashMap<Strin ...
分类:
其他好文 时间:
2020-06-24 20:02:55
阅读次数:
61
16. 最接近的三数之和 给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。 示例: 输入:nums = [-1,2,1,-4], target = 1 输出:2 ...
分类:
编程语言 时间:
2020-06-24 16:24:36
阅读次数:
36
题目地址 16. 最接近的三数之和 题目分析 这个题和三数之和很相似,所以我采用了相同的做法,先进行排序,每次固定左手边的值。然后使用双指针从左边和右边寻找三数之和最接近target的值,这样做的效率有点差,两个月过去了水平还没啥提升,我醉了。 实现代码 class Solution { publi ...
分类:
其他好文 时间:
2020-06-24 13:50:47
阅读次数:
36
解题思路排序之后就是字典序了,遇到单个字符,加到集合里,多个字符则看最后一个字符之前的字符是否已经在集合里,在的话,加进集合里,不在的话,可以直接不管了,因为已经排序,说明肯定无法一步一步的达到这个字符串,再用两个变量,保存首次遇到的最长长度,最后返回(有点重复代码) class Solution: ...
分类:
其他好文 时间:
2020-06-24 00:45:38
阅读次数:
82
一、分治法 时间复杂度:O(NlogN) 通过70%样例,超时 import java.util.*; public class Main { static int res = 0; static void solution(int[] a, int i, int j, int x) { if(i ...
分类:
其他好文 时间:
2020-06-24 00:41:01
阅读次数:
65
package LeetCode_268 /** * 268. Missing Number * https://leetcode.com/problems/missing-number/description/ * * Given an array containing n distinct nu ...
分类:
其他好文 时间:
2020-06-24 00:06:34
阅读次数:
63