Given a string S, the task is to check if a string is a non-repetitive or not.  A non-repetitive string is defined as a string that does not contain any different character between two same characters 
Example 1:
Input: S = "AABBCCCCC"
Output: 1
Explanation: No different character is 
placed between the two same characters.
Example 2:
Input: S = "ABA"
Output: 0
Explanation: B is in between two A's
Your Task:
You don't need to read input or print anything. Your task is to complete the function nonRepetitive() which takes a string S as input and returns the boolean value. 
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(constant).
Constraints:
1 <= |S| <= 10^{5}
S contains upper case English alphabets

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3

class Solution:
    def nonRepetitive(self, s):
        # code here


Solutions:
class Solution:

	def nonRepetitive(self, s):
		a = set()
		for i in range(len(s)):
			if s[i] not in a:
				a.add(s[i])
			elif s[i] != s[i - 1]:
				return False
		return True


class Solution:

	def nonRepetitive(self, s):
		c = ''
		current = s[0]
		for i in s[1:]:
			if i != current:
				c += current
				current = i
		c += current
		if len(c) != len(set(c)):
			return 0
		return 1


class Solution:

	def nonRepetitive(self, s):
		s = [*s]
		string = ''
		while s:
			while len(s) > 1 and s[-1] == s[-2]:
				s.pop()
			string += s.pop()
		return len(string) == len(set(string))


class Solution:

	def nonRepetitive(self, s):
		x = set()
		for i in range(len(s)):
			if s[i] not in x:
				x.add(s[i])
			elif s[i] != s[i - 1]:
				return 0
		return 1


class Solution:

	def nonRepetitive(self, s):
		start = {}
		end = {}
		n = len(s)
		for i in range(n):
			if s[i] not in start:
				start[s[i]] = i
				end[s[i]] = i
			else:
				end[s[i]] = i
		for k in start:
			for i in range(start[k], end[k] + 1):
				if s[i] != k:
					return False
		return True


class Solution:

	def nonRepetitive(self, s):
		m = {}
		n = len(s)
		for i in range(n):
			if s[i] not in m:
				m[s[i]] = i
			else:
				if m[s[i]] != i - 1:
					return False
				m[s[i]] = i
		return True


class Solution:

	def nonRepetitive(self, s):
		gg = {s[0]: 1}
		for (j, i) in enumerate(s):
			if j == 0:
				continue
			if s[j] == s[j - 1]:
				continue
			else:
				if i in gg:
					return 0
				elif i not in gg:
					gg[i] = 0
				gg[i] += 1
		return 1


class Solution:

	def nonRepetitive(self, s):
		d = {}
		n = len(s)
		for i in range(n):
			if s[i] in d:
				if i - d[s[i]] > 1:
					return 0
			d[s[i]] = i
		return 1


class Solution:

	def nonRepetitive(self, s):
		visited = [0] * 26
		i = 0
		n = len(s)
		while i < n - 1:
			if visited[ord(s[i]) - 65] == 1:
				return 0
			if i < n - 1 and s[i] == s[i + 1]:
				i += 1
			else:
				visited[ord(s[i]) - 65] = 1
				i += 1
		if visited[ord(s[-1]) - 65] == 1:
			return 0
		return 1
		return 0


class Solution:

	def nonRepetitive(self, s):
		x = []
		x.append(s[0])
		for i in range(1, len(s)):
			if s[i] == s[i - 1]:
				continue
			elif s[i] in x:
				return 0
			else:
				x.append(s[i])
		return 1