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 |
Tags
- AI 경진대회
- Docker
- 프로그래머스 파이썬
- hackerrank
- 편스토랑 우승상품
- programmers
- 더현대서울 맛집
- 금융문자분석경진대회
- ubuntu
- 데이콘
- 편스토랑
- 파이썬
- 캐치카페
- gs25
- 우분투
- PYTHON
- ChatGPT
- SW Expert Academy
- Git
- Baekjoon
- 맥북
- 프로그래머스
- dacon
- leetcode
- 자연어처리
- 코로나19
- Kaggle
- Real or Not? NLP with Disaster Tweets
- github
- 백준
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

SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'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 |