Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- java
- algorithms
- 성적프로그램
- If
- 서평
- 2020년 제4회 정보처리기사 필기 문제 분석
- Til
- 주간회고
- 스터디
- jsp
- sqldeveloper
- 필기
- 항해99
- 책리뷰
- 함수형 코딩
- Real MySQL
- LeetCode
- 코드숨
- 2020년 일정
- 정보처리기사
- Jackson
- git
- 뇌정리
- 회고
- 2020년 정보처리기사 4회
- 알고리즘
- 미니프로젝트
- Python
- post
- hackerrank
Archives
- Today
- Total
조컴퓨터
35. Search Insert Position 본문
for문을 돌리려고 했으나 for문보다는 인덱스 값 두 개와 조건 하나를 두어서 인덱스 값을 대입해 비교하는 쪽이 식을 세우기에 훨씬 수월했다.
class Solution {
public int searchInsert(int[] nums, int target) {
int i = 0;
int idx = 0;
while( i<nums.length ) {
if( nums[idx] < target ) {
idx++;
}
i++;
}
return idx;
}
}
'LeetCode > Algorithms' 카테고리의 다른 글
58. Length of Last Word (0) | 2021.10.28 |
---|---|
53. Maximum Subarray (0) | 2021.10.27 |
28. Implement strStr() (0) | 2021.10.20 |
27. Remove Element (0) | 2021.10.19 |
26. Remove Duplicates from Sorted Array (0) | 2021.10.17 |