| | | 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 | | |
| | | 12 | | namespace LeetCode.Algorithms.GuessNumberHigherOrLower; |
| | | 13 | | |
| | | 14 | | public abstract class GuessNumberHigherOrLower : IGuessNumberHigherOrLower |
| | | 15 | | { |
| | | 16 | | private readonly int _pickedNumber; |
| | | 17 | | |
| | 3 | 18 | | protected GuessNumberHigherOrLower(int pickedNumber) |
| | 3 | 19 | | { |
| | 3 | 20 | | _pickedNumber = pickedNumber; |
| | 3 | 21 | | } |
| | | 22 | | |
| | | 23 | | public abstract int GuessNumber(int n); |
| | | 24 | | |
| | | 25 | | public int Guess(int num) |
| | 5 | 26 | | { |
| | 5 | 27 | | if (num == _pickedNumber) |
| | 3 | 28 | | { |
| | 3 | 29 | | return 0; |
| | | 30 | | } |
| | | 31 | | |
| | 2 | 32 | | if (num < _pickedNumber) |
| | 1 | 33 | | { |
| | 1 | 34 | | return 1; |
| | | 35 | | } |
| | | 36 | | |
| | 1 | 37 | | return -1; |
| | 5 | 38 | | } |
| | | 39 | | } |