Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 자연어처리
- 금융문자분석경진대회
- 우분투
- 더현대서울 맛집
- Docker
- hackerrank
- 편스토랑 우승상품
- AI 경진대회
- SW Expert Academy
- Real or Not? NLP with Disaster Tweets
- ubuntu
- dacon
- 파이썬
- Git
- github
- 데이콘
- 편스토랑
- 코로나19
- PYTHON
- programmers
- Baekjoon
- 캐치카페
- leetcode
- 프로그래머스
- 프로그래머스 파이썬
- gs25
- 맥북
- ChatGPT
- Kaggle
- 백준
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1078. Occurrences After Bigram (Python) 본문
728x90
반응형
Given words first and second, consider occurrences in some text of the form "first second third", where second comes immediately after first, and third comes immediately after second.
For each such occurrence, add "third" to the answer, and return the answer.
Example 1:
Input: text = "alice is a good girl she is a good student", first = "a", second = "good"
Output: ["girl","student"]
Example 2:
Input: text = "we will we will rock you", first = "we", second = "will"
Output: ["we","rock"]
Note:
- 1 <= text.length <= 1000
- text consists of space separated words, where each word consists of lowercase English letters.
- 1 <= first.length, second.length <= 10
- first and second consist of lowercase English letters.
Solution
class Solution:
def findOcurrences(self, text: str, first: str, second: str) -> List[str]:
split_text = text.split(" ")
answer = []
for i in range(2, len(split_text)):
if split_text[i-2] == first and split_text[i-1] == second:
answer.append(split_text[i])
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 216. Combination Sum III (Python) (0) | 2020.10.23 |
---|---|
[leetCode] 206. Reverse Linked List (Python) (0) | 2020.10.22 |
[leetCode] 451. Sort Characters By Frequency (Python) (0) | 2020.10.20 |
[leetCode] 215. Kth Largest Element in an Array (Python) (0) | 2020.10.19 |
[leetCode] 347. Top K Frequent Elements (Python) (0) | 2020.10.14 |
Comments