< Summary

Information
Class: LeetCode.Algorithms.ImplementQueueUsingStacks.ImplementQueueUsingStacksTwoStacks
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ImplementQueueUsingStacks\ImplementQueueUsingStacksTwoStacks.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 70
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
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%
Push(...)100%44100%
Pop()100%11100%
Peek()100%11100%
Empty()100%11100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ImplementQueueUsingStacks\ImplementQueueUsingStacksTwoStacks.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 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.ImplementQueueUsingStacks;
 13
 14/// <inheritdoc />
 15public class ImplementQueueUsingStacksTwoStacks : IImplementQueueUsingStacks
 16{
 917    private readonly Stack<int> _stack = new();
 18
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O(n)
 22    /// </summary>
 23    /// <param name="x"></param>
 24    public void Push(int x)
 1425    {
 1426        var tempStack = new Stack<int>();
 27
 2628        while (_stack.Count > 0)
 1229        {
 1230            tempStack.Push(_stack.Pop());
 1231        }
 32
 1433        _stack.Push(x);
 34
 2635        while (tempStack.Count > 0)
 1236        {
 1237            _stack.Push(tempStack.Pop());
 1238        }
 1439    }
 40
 41    /// <summary>
 42    ///     Time complexity - O(1)
 43    ///     Space complexity - O(1)
 44    /// </summary>
 45    /// <returns></returns>
 46    public int Pop()
 847    {
 848        return _stack.Pop();
 749    }
 50
 51    /// <summary>
 52    ///     Time complexity - O(1)
 53    ///     Space complexity - O(1)
 54    /// </summary>
 55    /// <returns></returns>
 56    public int Peek()
 357    {
 358        return _stack.Peek();
 259    }
 60
 61    /// <summary>
 62    ///     Time complexity - O(1)
 63    ///     Space complexity - O(1)
 64    /// </summary>
 65    /// <returns></returns>
 66    public bool Empty()
 767    {
 768        return _stack.Count == 0;
 769    }
 70}