250x250
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
- Object Poling
- 플레이어 이동
- Object Pooling
- Prefabs
- LayerMark
- 2D슈팅게임
- Parallax
- 오브젝트 풀링
- Vector3
- 유니티
- CSharp #자료구조
- 프리팹
- rigidbody
- apk
- Transform
- Hpbar
- raycast
- Hp바
- 패럴렉스
- 일시정지
- Scrooling
- Animation State Machine
- 스크롤링
- raycasting
- Ainimation Blending
- 플레이어 방향전환
- Unity
- Blend Type
- joystick
- rotation
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.2 연속 부분 수열 합의 개수 본문
728x90
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;
}
}
728x90
'Programmers - C# > CodingTest 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 |