Given string s that is appended with a number at last. The task is to check whether the length of string excluding that number is equal to that number. 
Example 1:
Input:  s = "geeks5"
Output: 1
Explanation: Length of geeks is 5
and the last number is also 5.
Example 2:
Input:  s = "geek5"
Output: 0
Explanation: Length of geek is 4
and the last number is 5.
User Task:
Your task is to complete the function isSame() which takes a single string as input and returns 1 in case the answer is true, otherwise 0. You do not need to take any input or print anything.
Expected Time Complexity: O(|s|)
Expected Auxiliary Space: O(1)
Constraints:
1 <= |s| <= 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3
class Solution:
	def isSame(self, s):
		# code here

Solutions:
class Solution:

	def isSame(self, s):
		k = 'qwertyuiopasdfghjklmnbvcxzQWERTYUIOPLKJHGFDSAZXCVBNM'
		l = '1234567890'
		j = ''
		n = ''
		for i in range(len(s)):
			if s[i] in k:
				j = j + s[i]
			elif s[i] in l:
				n = n + s[i]
		if len(j) == int(n):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		count = 0
		num = ''
		for i in s:
			try:
				i = int(i)
			except:
				count += 1
		if int(s[count:len(s)]) == count:
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		s1 = s[::-1]
		a = ''
		for i in s1:
			try:
				b = int(i)
				a += i
			except:
				break
		a1 = ''
		a1 += ''.join(reversed(a))
		i = int(a1) + len(a1)
		if i == len(s):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		str1 = ''
		num = ''
		for i in range(len(s)):
			if s[i].isalpha() == True:
				str1 = str1 + s[i]
			elif int(s[i]) >= 0:
				num = num + s[i]
		num1 = int(num)
		if len(str1) == num1:
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		s1 = ''
		s2 = ''
		for i in s:
			if i.isalpha():
				s2 += i
			elif i.isdigit():
				s1 += i
		if len(s2) == int(s1):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		lettersLen = 0
		num = ''
		for i in range(len(s)):
			if s[i].isdigit():
				num += s[i]
			else:
				lettersLen += 1
		if int(num) == lettersLen:
			return 1
		return 0


class Solution:

	def isSame(self, s):
		c = 0
		for i in range(len(s)):
			if s[i].isalpha():
				c = c + 1
			elif c == int(s[i:]):
				return 1
			else:
				return 0


class Solution:

	def isSame(self, s):
		c = 0
		s2 = ''
		for i in s:
			if i.isalpha():
				c += 1
			if i.isdigit():
				s2 = s2 + i
		if c == int(s2):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		num_begin = 0
		for i in s:
			if ord(i) < 58:
				num_begin = s.index(i)
				break
		number = s[num_begin:]
		splitedtxt = s[:num_begin]
		return 1 if int(number) == len(splitedtxt) else 0


class Solution:

	def isSame(self, s):
		st = ''
		no = ''
		for i in s:
			if 'a' <= i <= 'z':
				st += i
			else:
				no += i
		if len(st) == int(no):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		a = ''
		b = ''
		for i in s:
			if i.isalpha():
				a += i
			elif int(i) in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
				b += i
		l = len(s) - len(b)
		if l == int(b):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		a = 'abcdefghijklmnopqrstuvwxyz'
		n = '0123456789'
		n_a = 0
		num = ''
		for i in s:
			if i in a:
				n_a += 1
			if i in n:
				num = num + i
		if n_a == int(num):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		n = len(s)
		cnt = 0
		for c in s:
			if c.isalpha():
				cnt += 1
		no = int(s[cnt:])
		return 1 if no == cnt else 0


class Solution:

	def isSame(self, s):
		no = str()
		for i in range(len(s)):
			if s[i].isdigit():
				no = no + s[i]
		new = s.replace(no, '')
		if len(new) == int(no):
			return 1
		else:
			return 0


import re

class Solution:

	def isSame(self, s):
		number = re.search('\\d+', s)
		if number == None:
			return 0
		else:
			(start, end) = number.span()
			if len(s[:start]) == int(number.group()):
				return 1
			else:
				return 0


class Solution:

	def isSame(self, s):
		a1 = ''
		a2 = ''
		for i in s:
			if i.isalpha():
				a2 = a2 + i
			elif i.isdigit():
				a1 = a1 + i
		if len(a2) == int(a1):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		temp = s
		num = ''
		for ch in temp:
			if ch.isnumeric():
				num += ch
				temp = temp.replace(ch, '')
		if len(temp) == int(num):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		str = ''
		for i in s:
			if i.isdigit():
				str += i
		if int(str) == len(s) - len(str):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		c = 0
		temp = '0'
		for i in s:
			if i.isdigit():
				temp += i
			else:
				c += 1
		if c == int(temp):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		num = ''
		while s[-1].isdigit():
			num = s[-1] + num
			s = s[:-1]
		if len(s) == int(num):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		count = ''
		digit = ''
		for i in range(len(s)):
			if s[i].isalpha() == True:
				count += s[i]
			elif s[i].isdigit() == True:
				digit += s[i]
		if len(count) == int(digit):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		strr = ''
		num = ''
		for i in s:
			if i.isnumeric():
				num += i
			else:
				strr += i
		if len(strr) == int(num):
			return 1
		else:
			return 0


import re

class Solution:

	def isSame(self, s):
		m = re.findall('[a-z]+|[0-9]+', s)
		if len(m[0]) == int(m[1]):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		n = 0
		l = len(s)
		inc = 1
		for i in range(l - 1, 0, -1):
			if s[i].isnumeric():
				n = n + inc * int(s[i])
				inc *= 10
				l -= 1
			else:
				break
		if l == n:
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		t = ''
		m = 0
		for i in range(len(s)):
			if s[i] in '0123456789':
				t += s[i]
				if not m:
					m = i
		if int(t) == m:
			return 1
		return 0


class Solution:

	def isSame(self, s):
		digit = ''
		charlen = 0
		for i in s:
			if i.isdigit():
				digit += i
			else:
				charlen += 1
		num = int(digit)
		if charlen == num:
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		l1 = list(s)
		string = ''
		number = ''
		for index in l1:
			if index.isnumeric():
				number += index
			else:
				string += index
		if len(string) == int(number):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		c = 0
		for i in s:
			if i.isdigit():
				break
			else:
				c += 1
		str2 = ''
		for i in s:
			if i.isdigit():
				str2 += i
		if int(str2.lstrip('0')) == c:
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		string = ''
		num = ''
		for i in s:
			if i.isalpha():
				string += i
			else:
				num += i
		if len(string) == int(num):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		str1 = ''
		str2 = ''
		for i in s:
			if i.isalpha():
				str1 += i
			elif i.isdigit():
				str2 += i
		if len(str1) == int(str2):
			return 1
		else:
			return 0


class Solution:

	def extract_digits(self, s):
		digits_string = ''
		for i in range(-1, -len(s), -1):
			if s[i].isdigit():
				digits_string = s[i] + digits_string
			else:
				break
		return int(digits_string)

	def len_of_string_without_digits(self, s):
		new_s = ''
		for i in range(len(s)):
			if s[i].isdigit():
				break
			else:
				new_s += s[i]
		return len(new_s)

	def isSame(self, s):
		if self.len_of_string_without_digits(s) == self.extract_digits(s):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		ans = ''
		c = 0
		for i in s:
			if i.isdigit():
				ans += i
				c += 1
		if len(s) - c == int(ans):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		ans = []
		s = list(s)
		i = len(s) - 1
		while i >= 0:
			if s[i].isnumeric():
				ans.insert(0, s[i])
			else:
				break
			i -= 1
		a = ''
		for i in ans:
			a += i
		if len(s) - len(ans) == int(a):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		l = ''
		l1 = ''
		for i in s:
			if i.isalpha():
				l = l + i
			elif i.isdigit():
				l1 = l1 + i
		if len(l) == int(l1):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		str_num = ''
		count = 0
		for i in s[::-1]:
			if i.isnumeric():
				str_num += i
				count += 1
			else:
				num = int(str_num[::-1])
				s = s[:len(s) - count]
				break
		if len(s) == num:
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		a = 0
		for i in range(0, len(s)):
			if s[i].isalpha():
				a = a + 1
		n = int(s[a:len(s)])
		if a == n:
			return 1
		return 0


class Solution:

	def isSame(self, s):
		c = 0
		for i in range(len(s)):
			if s[i].isalpha():
				c = c + 1
			else:
				break
		if s[c:].isdigit() and int(s[c:]) == c:
			return 1
		else:
			return 0


import re

class Solution:

	def isSame(self, s):
		num = re.findall('\\d+$', s)
		k = len(s) - len(num[0])
		if k >= int(num[0]):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		string = ''
		number = ''
		for char in s:
			if char.isdigit():
				number = number + char
			else:
				string = string + char
		if int(number) == len(string):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		count = 0
		for i in s:
			if i.isalpha():
				count += 1
		last_num = s[count:]
		if count == int(last_num):
			return '1'
		else:
			return '0'


class Solution:

	def isSame(self, s):
		c = 0
		d = ''
		for i in s:
			if i.isalpha():
				c = c + 1
			if i.isdigit():
				d = d + i
		if c == abs(int(d)):
			return 1
		else:
			return 0


import re

class Solution:

	def isSame(self, s):
		pattern = '\\d+$'
		num = sum(map(int, re.findall(pattern, s)))
		s = re.sub(pattern, '', s)
		return 1 if len(s) == num else 0


class Solution:

	def isSame(self, s):
		d = '0123456789'
		n = ''
		for i in s:
			if i in d:
				n += i
		if len(s[:len(s) - len(n)]) == int(n):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		c = 0
		k = ''
		for i in s:
			if i not in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
				c += 1
			else:
				k += i
		if c == int(k):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		v = '1234567890'
		x = len(s) - 2
		c = len(s) - 1
		while s[x] in v:
			c -= 1
			x -= 1
		if c == int(s[c:]):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		for x in range(len(s)):
			if s[x].isdigit():
				return int(len(s[:x]) == int(s[x:]))


class Solution:

	def isSame(self, s):
		al = ''
		n = ''
		for e in s:
			if e.isalpha():
				al += e
			else:
				n += e
		return 1 if len(al) == int(n) else 0


class Solution:

	def isSame(self, s):
		s = s[::-1]
		new = ''
		for i in s:
			if i.isdigit():
				new += i
			else:
				break
		N = new[::-1]
		str_part = s[len(N):]
		if int(N) == len(str_part):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		l = []
		m = []
		for i in s:
			if i.isalpha():
				l.append(i)
			else:
				m.append(i)
		an = len(l)
		ans = ''.join(m)
		ans = int(ans)
		if an == ans:
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		sum1 = []
		num = 0
		for i in s:
			if i.isalpha():
				sum1.append(i)
			else:
				num = num * 10 + int(i)
		if len(sum1) == num:
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		a = ''
		b = ''
		for i in s:
			if i.isalpha():
				a += i
			else:
				b += i
		if len(a) == int(b):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		length = len(s)
		for i in range(0, length):
			if s[i].isalpha():
				alphaLen = i + 1
		if alphaLen == int(s[alphaLen:]):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		res = ''
		ans = ''
		for i in range(len(s)):
			if s[i].islower() or s[i].isupper():
				res = res + s[i]
			else:
				ans = ans + s[i]
		if int(ans) == len(res):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		index = len(s) - 1
		while s[index].isnumeric():
			index -= 1
		else:
			if len(s[0:index + 1]) == int(s[index + 1:len(s)]):
				return 1
		return 0


class Solution:

	def isSame(self, s):
		dig_str = ''
		for i in range(len(s)):
			if s[i].isdigit():
				dig_str += s[i:]
				break
		if int(dig_str) == len(s) - len(dig_str):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		numbers = list('1234567890')
		cnt = 0
		num = ''
		for i in s:
			if i in numbers:
				num += i
				cnt += 1
		num = int(num)
		if num == len(s) - cnt:
			return 1
		return 0


class Solution:

	def isSame(self, s):
		z = ''
		x = ''
		for i in s:
			if i.isalpha():
				z = z + i
			else:
				x = x + i
		if len(z) == int(x):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		st = [i for i in s if not i.isdigit()]
		n = ''
		for i in range(len(s) - 1, 1, -1):
			if not s[i].isdigit():
				break
			n = s[i] + n
		return 1 if int(n) == len(st) else 0


import re

class Solution:

	def isSame(self, s):
		x = re.findall('[0-9]+', s)
		y = re.findall('[a-z]+', s.lower())
		z = ''.join(x)
		count = 0
		for i in y:
			for j in i:
				count = count + 1
		if int(z) == count:
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		x = ''.join((i for i in s[::-1] if i.isdigit()))[::-1]
		return int(len(s[:len(s) - len(x)]) == int(x))


class Solution:

	def isSame(self, s):
		n = len(s)
		c = 0
		s1 = ''
		for i in range(n - 1, -1, -1):
			if s[i].isdigit() == 1:
				s1 = s[i] + s1
				c += 1
			else:
				break
		n1 = int(s1)
		n = n - c
		if n == n1:
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		n = ''
		v = ''
		for ele in s:
			if ele.isalpha() == True:
				v = v + ele
			else:
				n = n + ele
		if len(v) == int(n):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		t = ''
		num = ''
		a = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
		for i in s:
			if i not in a:
				t += i
			else:
				num += i
		if len(t) == int(num):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		n = len(s)
		ans = ''
		for i in range(n):
			if s[i].isdigit():
				ans += s[i]
				s.replace(s[i], '')
		a = len(ans)
		if len(s[:n - a]) == int(ans):
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		c = 0
		r = ''
		for i in s:
			if i not in '0123456789':
				c += 1
			else:
				r += i
		for i in range(len(r)):
			if r[i] == '0':
				pass
			else:
				v = i
				break
		m = r[v:]
		if c == int(m):
			return 1
		return 0


class Solution:

	def isSame(self, s):
		b = ''
		for i in range(len(s) - 1, -1, -1):
			if s[i].isdigit() == True:
				b = s[i] + b
			else:
				j = i
				break
		if int(b) == j + 1:
			return 1
		return 0


class Solution:

	def isSame(self, s):
		a = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
		l = []
		for i in range(len(s)):
			l.append(s[i])
		x = []
		y = []
		for i in l:
			if i in a:
				x.append(i)
			else:
				y.append(i)
		a = ''.join(x)
		b = ''.join(y)
		n = len(b)
		m = int(a)
		if m == n:
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		for i in range(len(s)):
			if s[i].isnumeric():
				break
		k = int(s[i:])
		s = s[:i]
		if len(s) == k:
			return 1
		else:
			return 0


class Solution:

	def isSame(self, s):
		x = ''
		y = ''
		for i in s:
			if 'a' <= i >= 'z':
				x = x + i
			elif 'A' <= i >= 'Z':
				x = x + i
			else:
				y = y + i
		a = int(y)
		b = len(x)
		if a == b:
			return 1
		else:
			return 0