-
Notifications
You must be signed in to change notification settings - Fork 1
/
074_Stones on the Table.py
57 lines (36 loc) · 1.03 KB
/
074_Stones on the Table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Codewars Coding Challenge
Day 74/366
Level 7kyu
Stones on the Table
There are some stones on Bob's table in a row, and each of them can be red, green or blue, indicated by the characters R, G, and B.
Help Bob find the minimum number of stones he needs to remove from the table so that the stones in each pair of adjacent stones have different colors.
Examples:
"RGBRGBRGGB" => 1
"RGGRGBBRGRR" => 3
"RRRRGGGGBBBB" => 9
def solution(stones):
# Do some magic
https://www.codewars.com/kata/5f70e4cce10f9e0001c8995a/train/python
"""
# My Solution
def solution(stones):
count = 0
for i in range(1, len(stones)):
if stones[i] == stones[i - 1]:
count += 1
return count
# Test Cases
print(solution("RGBRGBRGGB")) # Output: 1
print(solution("RGGRGBBRGRR")) # Output: 3
print(solution("RRRRGGGGBBBB")) # Output: 9
"""
Solutions From Codewars
=1=
def solution(s):
st=[1 for i in range(1,len(s)) if s[i-1]==s[i]]
return sum(st)
=2=
def solution(s):
return sum(i==j for i,j in zip(s,s[1:]))
"""