Given an array A of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates). For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the final answer.
You may return the answer in any order.
class Solution:
def commonChars(self, A: List[str]) -> List[str]:
result = []
for i in range(len(A[0])):
result.append(A[0][i])
for j in range(1, len(A)):
if A[0][i] not in A[j]:
result.pop()
break
else:
# 한번 찾은 부분은 또 사용하면 안되니까 없애줌
tmp = A[j].index(A[0][i])
A[j] = A[j][:tmp] + A[j][tmp+1:]
return result
A[0]
을 기준으로 각 문자들이 모든 문자열에 있는지 확인
한번 찾은 부분은 또 사용하면 안되니까 잘라내줌
다른 괜찮은 방식 뭐 떠오르는게 없네요...
Balanced strings are those that have an equal quantity of 'L' and 'R' characters.
Given a balanced string s, split it in the maximum amount of balanced strings.
Return the maximum amount of split balanced strings.
class Solution:
def balancedStringSplit(self, s: str) -> int:
left = 0
right = 0
result = 0
for i in range(len(s)):
if s[i] == "L":
left += 1
if s[i] == "R":
right += 1
if left == right:
result += 1
return result
L
, R
개수 세줘서 같을때마다 result + 1