< 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>
 524    public DesignBrowserHistoryLinkedList(string homepage)
 525    {
 526        _current = new Node(homepage);
 527    }
 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)
 1035    {
 1036        _current.Next = new Node(url)
 1037        {
 1038            Previous = _current
 1039        };
 40
 1041        _current = _current.Next;
 1042    }
 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)
 951    {
 3852        for (var i = 0; i < steps; i++)
 1253        {
 1254            if (_current.Previous == null)
 255            {
 256                break;
 57            }
 58
 1059            _current = _current.Previous;
 1060        }
 61
 962        return _current.Value;
 963    }
 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)
 572    {
 1673        for (var i = 0; i < steps; i++)
 774        {
 775            if (_current.Next == null)
 476            {
 477                break;
 78            }
 79
 380            _current = _current.Next;
 381        }
 82
 583        return _current.Value;
 584    }
 85
 86    private sealed class Node
 87    {
 1588        public Node(string value)
 1589        {
 1590            Value = value;
 1591        }
 92
 1493        public string Value { get; }
 3294        public Node? Previous { get; set; }
 3095        public Node? Next { get; set; }
 96    }
 97}