public void checkPalindrome(string input)
{
string result = isPolindrome(input) ? "Yes, it's a Palindrome" : "No, it's not a Palindrome";
Console.WriteLine(result);
}
private bool isPolindrome(string input)
{
int halfLength = input.Length / 2;
for (int i = 0; i < halfLength; i++)
{
if (input[i] != input[input.Length - i - 1])
return false;
}
return true;
}
так получим наилучшую возможную сложность O(n / 2) и Ω(1) public async Task<PageItem> GetContent(string cat, bool offline)
{
try
{
if (offline)
{
var catId = int.Parse(cat);
var ctx = DataContext.Instance;
var data = (await ctx.Content.GetItems())
.First(x => x.CatId == catId);
var result = _mapper.Map<PageItem>(data);
result.Tab1 = ReplaceImages(result.Tab1);
result.Tab2 = ReplaceImages(result.Tab2);
result.Tab3 = ReplaceImages(result.Tab3);
result.FavUrl = $"{cat}";
return result;
}
else
{
//return $"{BaseUrl}content.php?cat={cat}&tab={tab}";
var da = new LoadDataAdapter();
var json = await da.GetJson(Settings.GetContent(cat));
var data = JsonConvert.DeserializeObject<PageItem>(json, new JsonBooleanConverter());
data.FavUrl = cat;
return data;
}
}
catch (Exception ex)
{
throw new ArgumentNullException("Ошибка загрузки.", ex);
}
}