Skip to content

Conversation

@cfriedt
Copy link
Owner

@cfriedt cfriedt commented Dec 6, 2020

https://leetcode.com/problems/linked-list-cycle-ii

time: 4ms
time-rank: 98.90%
time-complexity: O(N)

space: 7.8MB
space-rank: 89.71%
space-complexity: O(1)

This solution adds no extra space but destroys the input. While the cost of checking if a node is visited is still O(1), this solution is faster than an unordered_set<LinkedList*> lookup because no hashing is performed, values are likely still in cache, and it is simply a const comparison.

Fixes #228

https://leetcode.com/problems/linked-list-cycle-ii

time: 16ms
time-rank: 21.04%
time-complexity: O(N)

space: 10MB
space-rank: 9.36%
space-complexity: O(N)

Fixes #228

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
@cfriedt cfriedt self-assigned this Dec 6, 2020
https://leetcode.com/problems/linked-list-cycle-ii

time: 4ms
time-rank: 98.90%
time-complexity: O(N)

space: 7.8MB
space-rank: 89.71%
space-complexity: O(1)

This solution adds no extra space but destroys the input.
While the cost of checking if a node is visited is still O(1), this solution
is faster than an unordered_set<LinkedList*> lookup because no hashing is
performed, values are likely still in cache, and it is simply a const
comparison.

Fixes #228

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
@cfriedt cfriedt force-pushed the linked-list-cycle-ii branch from 88d2c52 to 77a8eeb Compare December 6, 2020 18:42
@codecov-io
Copy link

codecov-io commented Dec 6, 2020

Codecov Report

Merging #229 (77a8eeb) into master (52fa04b) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #229      +/-   ##
==========================================
+ Coverage   97.20%   97.22%   +0.02%     
==========================================
  Files          96       98       +2     
  Lines        2538     2557      +19     
==========================================
+ Hits         2467     2486      +19     
  Misses         71       71              
Impacted Files Coverage Δ
linked-list-cycle-ii.cpp 100.00% <100.00%> (ø)
split-a-string-in-balanced-strings.cpp 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52fa04b...77a8eeb. Read the comment docs.

@cfriedt cfriedt merged commit 4564226 into master Dec 6, 2020
@cfriedt cfriedt deleted the linked-list-cycle-ii branch December 6, 2020 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement linked-list-cycle-ii

3 participants