Given a string, check if all its characters are the same or not.
Example 1:
Input:
s = "geeks"
Output: False
Explanation: The string contains different
character 'g', 'e', 'k' and 's'.
Example 2:
Input: 
s = "gggg"
Output: True
Explanation: The string contains only one
character 'g'.
Your Task:
You don't need to read input or print anything. Your task is to complete the function check() which takes a string as input and returns True if all the characters in the string are the same. Else, it returns False.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
Constraints:
1 <= |S| <= 10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3



class Solution:

    def check (self,s):

        # your code here

Solutions:
class Solution:

	def check(self, s):
		d = set(s)
		if len(d) == 1:
			return True
		return False


class Solution:

	def check(self, s):
		if s.count(s[0]) == len(s):
			return True
		else:
			return False


class Solution:

	def check(self, s):
		k = s[0]
		for i in s[1:]:
			if i != k:
				return False
		return True


class Solution:

	def check(self, s):
		a = set(list(s))
		if len(a) == 1:
			return True
		else:
			return False


class Solution:

	def check(self, s):
		return len(s) == s.count(s[0])


class Solution:

	def check(self, S):
		return all((char == S[0] for char in S))


class Solution:

	def check(self, s):
		for i in range(len(s) - 1):
			if s[i] != s[i + 1]:
				return False
		return True


class Solution:

	def check(self, s):
		return len(set(s)) == 1


class Solution:

	def check(self, s):
		a = s[0]
		for i in s:
			if i == a:
				continue
			else:
				return False
		return True


class Solution:

	def check(self, s):
		e = s[0]
		ret_val = True
		for i in s:
			if i != e:
				ret_val = False
		return ret_val


class Solution:

	def check(self, s):
		ch = s[0]
		for i in s:
			if i != ch:
				return False
		return True


class Solution:

	def check(self, s):
		c = s[0]
		l = len(s)
		for i in range(1, l):
			if s[i] == s[0]:
				continue
			else:
				return False
		return True


class Solution:

	def check(self, s):
		count = 0
		l = len(s)
		s1 = s[0]
		for i in range(l):
			if s[i] != s1:
				count += 1
				break
		if count > 0:
			return False
		else:
			return True


class Solution:

	def check(self, s):
		flag = True
		for i in range(len(s) - 1):
			if s[i] != s[i + 1]:
				flag = False
				break
			else:
				flag = True
		if flag == True:
			return True
		else:
			return False


class Solution:

	def check(self, s):
		se = set(s)
		if len(se) == 1:
			return True
		else:
			return False


class Solution:

	def check(self, s):
		l = len(s)
		c = s.count(s[0])
		if l == c:
			return 1
		else:
			return 0


from collections import Counter

class Solution:

	def check(self, s):
		x = Counter(s)
		if len(Counter(x.keys())) == 1:
			return 'True'


class Solution:

	def check(self, s):
		dt = {}
		for i in s:
			dt[i] = 1
		if len(dt) == 1:
			return True
		else:
			return False


class Solution:

	def check(self, s):
		a = len(s)
		for i in range(len(s)):
			if s[0] != s[i]:
				return False
				break
		else:
			return True


class Solution:

	def check(self, s):
		for char in s:
			if s[0] != char:
				return False
		return True


class Solution:

	def check(self, s):
		return s.count(s[0]) == len(s)
		print('NO')
	check('self', 'geeks')


class Solution:

	def check(self, s):
		se = set()
		se.add(s[0])
		for i in s:
			if i not in se:
				return False
		return True


class Solution:

	def check(self, s):
		return all((char == s[0] for char in s))


class Solution:

	def check(self, s):
		l = list(s)
		st = set(l)
		if len(st) == 1:
			return True
		return False


class Solution:

	def check(self, s):
		first = s[0]
		for i in s:
			if i != first:
				return False
				break
		else:
			return True


class Solution:

	def check(self, s):
		for element in range(len(s)):
			if s[element] != s[0]:
				return False
		else:
			return True


class Solution:

	def check(self, s):
		inp_str_list = set(s.strip(''))
		if len(inp_str_list) == 1:
			return True
		else:
			return False


class Solution:

	def check(self, s):
		for i in range(len(s) - 1):
			if s[i] != s[i + 1]:
				return 0
		return 1


class Solution:

	def check(self, s):
		for i in s:
			if s.count(i) == len(s):
				return True
			else:
				return False


class Solution:

	def check(self, s):
		first_s = s[0]
		for i in s:
			if i == first_s:
				pass
			else:
				return False
		return True


from operator import countOf

class Solution:

	def check(self, s):
		s = list(s)
		if countOf(s, s[0]) == len(s):
			return True
		else:
			return False