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 |
Tags
- 코딩테스트
- 2870번
- c++
- Lv2
- 백준 1103번 c++
- 2870번 수학숙제 c++
- 백준 1103번 게임
- 백준 c++ 2870번
- 백준
- dfs
- 2870번 수학숙제
- 코테
- Unity
- Lv.3
- 수학숙제
- 2468 c++
- 백준 17070번 c++
- 프로그래머스
- Beakjoon
- 백준 c++ 2468번
- C#
- 백준 1103번
- 백준 2870번
- 2870번 c++
- 백준 17070번
- 17070번
- 오브젝트 풀링
- 플레이어 이동
- Algorithm
- 유니티
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.2 연속 부분 수열 합의 개수 본문
https://school.programmers.co.kr/learn/courses/30/lessons/131701
1. 정답코드 및 핵심 아이디어, 유의사항
- 수열 + HashSet<T>
https://godgjwnsgur7.tistory.com/46
using System;
using System.Collections.Generic;
public class Solution
{
public int solution(int[] elements)
{
List<int> list = new List<int>(elements);
HashSet<int> hashSet = new HashSet<int>();
// elements를 한번 더 넣어서 따로 끝 인덱스를 0번과 이어주지 않게 함
for (int i = 0; i < elements.Length - 1; i++)
list.Add(elements[i]);
for (int i = 0; i < elements.Length; i++)
{
int num = 0;
for (int j = 0; j < elements.Length; j++)
{
num += list[i + j]; // 현재 인덱스 + 더해나갈 인덱스
hashSet.Add(num);
}
}
return hashSet.Count;
}
}
'CodingTest > Programmers Lv.2' 카테고리의 다른 글
[프로그래머스 C#] Lv.2 기능개발 (0) | 2023.09.03 |
---|---|
[프로그래머스 C#] Lv.2 연속된 부분 수열의 합 (0) | 2023.08.30 |
[프로그래머스 C#] Lv.2 귤 고르기 (0) | 2023.08.25 |
[프로그래머스 C#] Lv.2 k진수에서 소수 개수 구하기 (0) | 2023.08.25 |
[프로그래머스 C#] Lv.2 호텔 대실 (0) | 2023.08.23 |