| | 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 | |
|
| | 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 | | // ReSharper disable once InconsistentNaming |
| | 26 | | public int guess(int num) |
| 5 | 27 | | { |
| 5 | 28 | | if (num == _pickedNumber) |
| 3 | 29 | | { |
| 3 | 30 | | return 0; |
| | 31 | | } |
| | 32 | |
|
| 2 | 33 | | if (num < _pickedNumber) |
| 1 | 34 | | { |
| 1 | 35 | | return 1; |
| | 36 | | } |
| | 37 | |
|
| 1 | 38 | | return -1; |
| 5 | 39 | | } |
| | 40 | | } |