Given an integer, return its base 7 string representation.

Example 1:

Input: 100
Output: "202"



Example 2:

Input: -7
Output: "-10"



Note:
The input will be in range of [-1e7, 1e7].

Difficulty: EASY
Starter code: class Solution:
    def convertToBase7(self, num: int) -> str:
        

Solutions:
class Solution:

	def convertToBase7(self, num):
		if num < 0:
			return '-' + str(self.convertToBase7(-num))
		elif num < 7:
			return str(num)
		else:
			return str(self.convertToBase7(num // 7)) + str(num % 7)


class Solution:

	def convertToBase7(self, num):
		L = []
		n = abs(num)
		while n >= 7:
			L.append(str(n % 7))
			n = n // 7
		L.append(str(n))
		return ''.join(L[::-1]) if num >= 0 else '-' + ''.join(L[::-1])


class Solution:

	def convertToBase7(self, num):
		flag = 0
		if num < 0:
			num = -num
			flag = 1
		elif num == 0:
			return '0'
		temp = num
		list1 = []
		while temp > 0:
			num = temp % 7
			temp = temp // 7
			list1.insert(0, str(num))
		if flag == 1:
			list1.insert(0, '-')
		str1 = ''.join(list1)
		return str1


class Solution:

	def convertToBase7(self, num):
		if num < 0:
			return '-' + self.convertToBase7(-num)
		if num < 7:
			return str(num)
		return self.convertToBase7(num // 7) + str(num % 7)


class Solution:

	def convertToBase7(self, num):
		if num == 0:
			return '0'
		sign = '-' if num < 0 else ''
		res = ''
		num = abs(num)
		while num > 0:
			res = str(num % 7) + res
			num //= 7
		return sign + res


class Solution:

	def convertToBase7(self, num):
		if num < 0:
			num *= -1
			r = '-'
		else:
			r = ''
		n = num
		c = 0
		while n // 7 > 0:
			c += 1
			n //= 7
		for i in range(c, 0, -1):
			t = num // 7 ** i
			if t > 0:
				num -= 7 ** i * t
				r += str(t)
			else:
				r += '0'
		r += str(num)
		return r


class Solution:

	def convertToBase7(self, num):
		minus = True if num < 0 else False
		num = abs(num)
		s = ''
		while num >= 7:
			s += str(num % 7)
			num //= 7
		s += str(num)
		return minus * '-' + s[::-1]


class Solution:

	def convertToBase7(self, num):
		a = ''
		n = False
		if num == 0:
			return '0'
		if num < 0:
			num = -num
			n = True
		while num != 0:
			a = str(num % 7) + a
			num //= 7
		if n == True:
			return '-' + a
		return a


class Solution:

	def convertToBase7(self, num):
		ans = ''
		num1 = abs(num)
		while num1:
			ans = str(num1 % 7) + ans
			num1 //= 7
		if num < 0:
			return '-' + ans
		elif num == 0:
			return '0'
		return ans


class Solution:

	def convertToBase7(self, num):

		def decTo7(n):
			new = ''
			while n / 7 != 0:
				new += str(n % 7)
				n //= 7
			if new == '':
				return '0'
			return new[::-1]
		if num >= 0:
			return decTo7(num)
		else:
			return '-' + decTo7(abs(num))


class Solution:

	def convertToBase7(self, num):
		if num < 0:
			negative = '-'
			num *= -1
		else:
			negative = ''
		p = 1
		while p <= num:
			p *= 7
		p = p // 7
		digits = []
		while p > 1:
			digits.append(num // p)
			num = num % p
			p = p // 7
		digits.append(num)
		result = negative + ''.join([str(x) for x in digits])
		return result