반응형

프로그래머스_C#/Level_2 17

[프로그래머스 C#] 주식가격

https://programmers.co.kr/learn/courses/30/lessons/42584 코딩테스트 연습 - 주식가격 초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요. 제한사항 prices의 각 가격은 1 이상 10,00 programmers.co.kr using System; public class Solution { public int[] solution(int[] prices) { int length = prices.Length; int[] answer = new int[length]; for (int i = -1; ++i < length;) for (int j =..

[프로그래머스 C#] 전력망을 둘로 나누기

https://programmers.co.kr/learn/courses/30/lessons/86971 코딩테스트 연습 - 전력망을 둘로 나누기 9 [[1,3],[2,3],[3,4],[4,5],[4,6],[4,7],[7,8],[7,9]] 3 7 [[1,2],[2,7],[3,7],[3,4],[4,5],[6,7]] 1 programmers.co.kr using System; using System.Collections.Generic; using System.Linq; public class Solution { public int solution(int n, int[,] wires) { int answer = -1; int[] _count = new int[2]; List _link1 = new List(); ..

[프로그래머스 C#] 모음사전

https://programmers.co.kr/learn/courses/30/lessons/84512 코딩테스트 연습 - 모음사전 사전에 알파벳 모음 'A', 'E', 'I', 'O', 'U'만을 사용하여 만들 수 있는, 길이 5 이하의 모든 단어가 수록되어 있습니다. 사전에서 첫 번째 단어는 "A"이고, 그다음은 "AA"이며, 마지막 단어는 "UUUUU"입니 programmers.co.kr using System; public class Solution { public int solution(string word) { int answer = 0; string _useWords = "AEIOU"; int[] _index = new int[_useWords.Length]; _index[0] = 1; for..

[프로그래머스 C#] 이진 변환 반복하기

https://programmers.co.kr/learn/courses/30/lessons/70129 코딩테스트 연습 - 이진 변환 반복하기 programmers.co.kr using System; using System.Linq; public class Solution { public int[] solution(string s) { int[] answer = new int[2]; while (s != "1") { answer[0] += 1; int oldLength = s.Length; int temp = s.ToList().RemoveAll(x => x == '0'); answer[1] += temp; s = Convert.ToString(oldLength - temp, 2); } return ans..

[프로그래머스 C#] 점프와 순간 이동

https://programmers.co.kr/learn/courses/30/lessons/12980?language=csharp 코딩테스트 연습 - 점프와 순간 이동 OO 연구소는 한 번에 K 칸을 앞으로 점프하거나, (현재까지 온 거리) x 2 에 해당하는 위치로 순간이동을 할 수 있는 특수한 기능을 가진 아이언 슈트를 개발하여 판매하고 있습니다. 이 아이언 슈 programmers.co.kr using System; class Solution { public int solution(int n) { int answer = 1; while (n != 1) { if (n % 2 == 0) n /= 2; else { n -= 1; ++answer; } } return answer; } } 어찌 됐든 1칸은..

[프로그래머스 C#] n^2 배열 자르기

https://programmers.co.kr/learn/courses/30/lessons/87390 코딩테스트 연습 - n^2 배열 자르기 정수 n, left, right가 주어집니다. 다음 과정을 거쳐서 1차원 배열을 만들고자 합니다. n행 n열 크기의 비어있는 2차원 배열을 만듭니다. i = 1, 2, 3, ..., n에 대해서, 다음 과정을 반복합니다. 1행 1열부 programmers.co.kr public class Solution { public int[] solution(int n, long left, long right) { int[] answer = new int[right - left + 1]; int indexAnswer = 0; for (long i = left / n; ++i

[프로그래머스 C#] 쿼드압축 후 개수 세기

https://programmers.co.kr/learn/courses/30/lessons/68936 코딩테스트 연습 - 쿼드압축 후 개수 세기 [[1,1,0,0],[1,0,0,0],[1,0,0,1],[1,1,1,1]] [4,9] [[1,1,1,1,1,1,1,1],[0,1,1,1,1,1,1,1],[0,0,0,0,1,1,1,1],[0,1,0,0,1,1,1,1],[0,0,0,0,0,0,1,1],[0,0,0,0,0,0,0,1],[0,0,0,0,1,0,0,1],[0,0,0,0,1,1,1,1]] [10,15] programmers.co.kr public class Solution { int[] answer = new int[] {0, 0}; public int[] solution(int[,] arr) { Quad..

[프로그래머스 C#] 스킬트리

https://programmers.co.kr/learn/courses/30/lessons/49993 코딩테스트 연습 - 스킬트리 programmers.co.kr using System.Text; public class Solution { public int solution(string skill, string[] skill_trees) { int answer = 0; for (int i = -1; ++i < skill_trees.Length;) { string cur_skill = skill_trees[i]; StringBuilder selectSkill = new StringBuilder(); for (int j = -1; ++j < cur_skill.Length;) if (skill.Contains..

[프로그래머스 C#] 방문 길이

https://programmers.co.kr/learn/courses/30/lessons/49994 코딩테스트 연습 - 방문 길이 programmers.co.kr using System; public class Solution { public int solution(string dirs) { int answer = 0; int[,,,] _check = new int[11, 11, 11, 11]; int _x = 5, _y = 5; for (int i = -1; ++i < dirs.Length;) { int oldX = _x, oldY = _y; char direction = dirs[i]; if (direction == 'U') ++_y; if (direction == 'D') --_y; if (dir..

[프로그래머스 C#] 올바른 괄호

https://programmers.co.kr/learn/courses/30/lessons/12909 코딩테스트 연습 - 올바른 괄호 괄호가 바르게 짝지어졌다는 것은 '(' 문자로 열렸으면 반드시 짝지어서 ')' 문자로 닫혀야 한다는 뜻입니다. 예를 들어 "()()" 또는 "(())()" 는 올바른 괄호입니다. ")()(" 또는 "(()(" 는 올바르지 않은 programmers.co.kr using System; public class Solution { public bool solution(string s) { bool answer = true; if (s[0] == ')' || s[s.Length - 1] == '(') return false; int _check = 0; for (int i = -..

반응형