public class Solution { public string ConvertToBase7(int num) { var prefix = num >= 0 ? "" : "-"; var list = new List<string>(); StringBuilder sb = new StringBuilder(); num = Math.Abs(num); do { var n = num % 7; sb.Append(n.ToString()); num = num / 7; } while (num != 0); var result = sb.ToString() + prefix; var list2 = result.Reverse(); sb.Clear(); foreach (var c in list2) { sb.Append(c); } return sb.ToString(); } }