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
- Real or Not? NLP with Disaster Tweets
- 백준
- hackerrank
- programmers
- 프로그래머스
- 편스토랑
- Docker
- 금융문자분석경진대회
- SW Expert Academy
- 프로그래머스 파이썬
- 자연어처리
- Git
- github
- gs25
- AI 경진대회
- 우분투
- leetcode
- 맥북
- dacon
- 캐치카페
- ChatGPT
- 파이썬
- 데이콘
- Baekjoon
- 더현대서울 맛집
- 편스토랑 우승상품
- ubuntu
- 코로나19
- Kaggle
- PYTHON
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 35. Search Insert Position (Python) 본문
728x90
반응형

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
Example 1:
Input: [1,3,5,6], 5
Output: 2
Example 2:
Input: [1,3,5,6], 2
Output: 1
Example 3:
Input: [1,3,5,6], 7
Output: 4
Example 4:
Input: [1,3,5,6], 0
Output: 0
Solution
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
if target in nums:
return nums.index(target)
else:
cnt = 0
for i in nums:
if i > target :
return cnt
cnt = cnt + 1
return len(nums)



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] 345. Reverse Vowels of a String (Python) (0) | 2020.08.07 |
|---|---|
| [leetCode] 448. Find All Numbers Disappeared in an Array (Python) (0) | 2020.08.06 |
| [leetCode] 290. Word Pattern (Python) (0) | 2020.08.04 |
| [leetCode] 205. Isomorphic Strings (Python) (0) | 2020.08.03 |
| [leetCode] 434. Number of Segments in a String (Python) (0) | 2020.08.02 |
Comments