Given an n-digit large number in form of string, check whether it is divisible by 7 or not. Print 1 if divisible by 7, otherwise 0.
Example 1:
Input: num = "8955795758"
Output: 1
Explanation: 8955795758 is divisible
by 7.
Example 2:
Input: num = "1000"
Output: 0
Explanation: 1000 is not divisible
by 7.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function isdivisible7Ã¢â¬â¹() which takes the string num as inputs and returns the answer.
Expected Time Complexity: O(|num|)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ |num| ≤ 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3



class Solution:

    def isdivisible7(self, num):

        # code here

Solutions:
class Solution:

	def isdivisible7(self, num):
		if int(num) % 7 == 0:
			return 1
		else:
			return 0


class Solution:

	def isdivisible7(self, num):
		num1 = ''
		for i in range(len(num)):
			if num[i].isnumeric() == True:
				num1 = num1 + num[i]
			else:
				return 0
		num2 = int(num1)
		if num2 % 7 == 0:
			return 1
		else:
			return 0


class Solution:

	def isdivisible7(self, num):
		ele = int(num[:-1])
		unit = 2 * int(num[-1])
		diff = ele - unit
		if diff % 7 == 0:
			return 1
		return 0


class Solution:

	def isdivisible7(self, num):
		a = str(num)
		if len(a) >= 3:
			lst = a[-1]
			fst = a[:-1]
			if (int(fst) - int(lst) * 2) % 7 == 0:
				return 1
			else:
				return 0
		elif int(a) % 7 == 0:
			return 1
		else:
			return -1


class Solution:

	def isdivisible7(self, num):
		return int(not int(num) % 7)


class Solution:

	def isdivisible7(self, num):
		ldigit = int(num[-1:]) * 2
		remNum = int(num[:-1])
		diff = remNum - ldigit
		if diff % 7 == 0:
			return 1
		else:
			return 0


class Solution:

	def isdivisible7(self, num):
		unit = int(num[-1]) * 2
		remaining = int(num[:-1])
		number = remaining - unit
		if number % 7 == 0:
			return 1
		else:
			return 0


class Solution:

	def isdivisible7(self, n):
		try:
			n = int(n)
			if n % 7 == 0:
				return 1
			return 0
		except:
			return 0


class Solution:

	def isdivisible7(self, num):
		m = int(num[:-1])
		o = 2 * int(num[-1])
		r = m - o
		if r % 7 == 0:
			return 1
		return 0


class Solution:

	def isdivisible7(self, num):
		int_num = int(num)
		if not int_num % 7:
			return 1
		return 0


def div(n):
	while n > 500:
		r = n % 10
		n = n // 10
		n -= 2 * r
	return n

class Solution:

	def isdivisible7(self, num):
		n = int(num)
		a = n
		if a == 0:
			return 0
		if a % 7 == 0:
			return 1
		else:
			return 0


class Solution:

	def isdivisible7(self, num):
		last_digit = int(num[-1])
		new_num = int(num[0:len(num) - 1])
		new_num = new_num - last_digit * 2
		if new_num % 7 == 0:
			return 1
		else:
			return 0


class Solution:

	def isdivisible7(self, num):
		n = len(num)
		unit = int(num[-1]) * 2
		rem = num[:n - 1]
		d = int(rem) - unit
		if d % 7 == 0:
			return 1
		else:
			return 0


class Solution:

	def isdivisible7(self, num):
		return int(int(num) % 7 == 0)