Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
linked-list-components.py 642 Bytes
Copy Edit Raw Blame History
Allen Liu authored 2018-10-13 01:56 +08:00 . add complexity
# Time: O(m + n), m is the number of G, n is the number of nodes
# Space: O(m)
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class Solution(object):
def numComponents(self, head, G):
"""
:type head: ListNode
:type G: List[int]
:rtype: int
"""
lookup = set(G)
dummy = ListNode(-1)
dummy.next = head
curr = dummy
result = 0
while curr and curr.next:
if curr.val not in lookup and curr.next.val in lookup:
result += 1
curr = curr.next
return result
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search