< Summary

Information
Class: LeetCode.Algorithms.DesignBrowserHistory.DesignBrowserHistoryLinkedList
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DesignBrowserHistory\DesignBrowserHistoryLinkedList.cs
Line coverage
100%
Covered lines: 38
Uncovered lines: 0
Coverable lines: 38
Total lines: 97
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Visit(...)100%11100%
Back(...)100%44100%
Forward(...)100%44100%
.ctor(...)100%11100%
get_Value()100%11100%
get_Previous()100%11100%
get_Next()100%11100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DesignBrowserHistory\DesignBrowserHistoryLinkedList.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2026 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.DesignBrowserHistory;
 13
 14/// <inheritdoc />
 15public sealed class DesignBrowserHistoryLinkedList : IDesignBrowserHistory
 16{
 17    private Node _current;
 18
 19    /// <summary>
 20    ///     Time complexity - O(1)
 21    ///     Space complexity - O(1)
 22    /// </summary>
 23    /// <param name="homepage"></param>
 124    public DesignBrowserHistoryLinkedList(string homepage)
 125    {
 126        _current = new Node(homepage);
 127    }
 28
 29    /// <summary>
 30    ///     Time complexity - O(1)
 31    ///     Space complexity - O(1)
 32    /// </summary>
 33    /// <param name="url"></param>
 34    public void Visit(string url)
 435    {
 436        _current.Next = new Node(url)
 437        {
 438            Previous = _current
 439        };
 40
 441        _current = _current.Next;
 442    }
 43
 44    /// <summary>
 45    ///     Time complexity - O(n), where n is the number of steps
 46    ///     Space complexity - O(1)
 47    /// </summary>
 48    /// <param name="steps"></param>
 49    /// <returns></returns>
 50    public string Back(int steps)
 451    {
 1852        for (var i = 0; i < steps; i++)
 653        {
 654            if (_current.Previous == null)
 155            {
 156                break;
 57            }
 58
 559            _current = _current.Previous;
 560        }
 61
 462        return _current.Value;
 463    }
 64
 65    /// <summary>
 66    ///     Time complexity - O(n), where n is the number of steps
 67    ///     Space complexity - O(1)
 68    /// </summary>
 69    /// <param name="steps"></param>
 70    /// <returns></returns>
 71    public string Forward(int steps)
 272    {
 673        for (var i = 0; i < steps; i++)
 274        {
 275            if (_current.Next == null)
 176            {
 177                break;
 78            }
 79
 180            _current = _current.Next;
 181        }
 82
 283        return _current.Value;
 284    }
 85
 86    private sealed class Node
 87    {
 588        public Node(string value)
 589        {
 590            Value = value;
 591        }
 92
 693        public string Value { get; }
 1594        public Node? Previous { get; set; }
 1195        public Node? Next { get; set; }
 96    }
 97}