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
- dfs
- 카카오
- 스택
- 코테
- 그래프 자바
- 리트코드 1557
- 인텔리제이 에러
- 자바
- daily challenge
- 파이썬
- leetcode 1721
- 구현
- java 프로그래머스
- 자바 리트코드
- java leetcode
- 백준 16935
- Java
- leetcode
- 코딩테스트
- 리트코드
- BFS
- 프로그래머스
- 리트코드 자바
- DP
- 자바 5464
- 분할정복
- 스프링 에러
- 백준 18222
- 백준
- 프로그래머스 java
Archives
- Today
- Total
레벨업 일지
[Java] leetcode 1523. Count Odd Numbers in an Interval Range 본문
알고리즘/leetcode
[Java] leetcode 1523. Count Odd Numbers in an Interval Range
24시간이모자란 2023. 2. 13. 23:04문제
https://leetcode.com/problems/count-odd-numbers-in-an-interval-range/description/
풀이
쉬어가는 문제.
로직은 다음과 같다.
- [ 0 .. low ] 0이상 low 이하 의 홀수 개수 를 구한다.
- [ 0 .. high ] 0 이상 high 이하의 홀수 개수를 구한다.
- 두개의 차를 해주고, low 가 홀수이면 1을 더해준다.
코드
class Solution {
public int countOdds(int low, int high) {
return (high+1) /2 - (low+1) /2 +low%2;
}
}
'알고리즘 > leetcode' 카테고리의 다른 글
[Java] leetcode 37. Sudoku Solver (2) | 2023.02.20 |
---|---|
[Java] leetcode 103. Binary Tree Zigzag Level Order Traversal (0) | 2023.02.19 |
[Java] leetcode 1626. Best Team With No Conflicts (0) | 2023.02.12 |
[Java] leetcode 1626. Best Team With No Conflicts (0) | 2023.02.01 |
[Java/Python] leetcode 1137. N-th Tribonacci Number (0) | 2023.01.31 |
Comments