"If you do nothing, nothing will happen."

2023/02/20 34

Please enable desugaring by adding the following to build.gradle 오류

2019-08-10 글쓴이 TED HONG Please enable desugaring by adding the following to build.gradle 오류 안드로이드 스튜디오에서 빌드시에 오류가 났다. 오류 메세지는 Please enable desugaring by adding the following to build.gradle 이것. 원인을 살펴보니 안드로이드 스튜디오에서 Java 8 을 사용하도록 설정하지 않아서였다. 프로젝트 우클릭 -> Open Module Settion (F4) 메뉴 -> Modules 에서 Source와 Target Compatibility 를 1.8 로 변경해주니 해결~

프로그래밍 2023.02.20

[Programmers] K번째 수

2019-07-19 글쓴이 TED HONG [Programmers] K번째 수 배열 array의 i번째 숫자부터 j번째 숫자까지 자르고 정렬했을 때, k번째에 있는 수를 구하는 문제 JAVA public static int[] solution(int[] array, int[][] commands) { int cnt = commands.length; int[] answer = new int[cnt]; for(int i = 0; i < cnt; ++i){ answer[i] = getSelectValue(array, commands[i]); } //System.out.println("answer ="+Arrays.toString(answer)); return answer; } static int getSele..

프로그래밍 2023.02.20

[HackerRank] Number of ID

2019-07-16 글쓴이 TED HONG [HackerRank] Number of ID Input값은 숫자로 된 문자열. 이를 재조합 하여 사원 번호를 만든다고 가정할 때 몇개를 만들 수 있는지 찾는 문제. 조건 1 : 사원번호는 8로 시작함 조건 2 : 사원번호는 11자리 숫자로 구성됨 public static int numOfIds(string pool) { List list = new List(pool.ToCharArray()); //int firstIdx = list.IndexOf('8')+ 1; int cnt = list.Count;// - firstIdx; int d = cnt / 11; int r = cnt % 11; Console.WriteLine(string.Format("firstId..

프로그래밍 2023.02.20

[HackerRank] Common Child

2019-06-21 글쓴이 TED HONG [HackerRank] Common Child 주어진 두 문자열중 중복되는 문자를 찾고 연속으로 가장 길게 배치되는 글자 수를 찾는 문제. (문제 이해하기가 어렵다;;;) List에 넣어서 하나 하나 비교하는 방식으로 하다가 자꾸 오답이 나서 보니 문제를 잘못이해함.. ㅠ 멘붕와서 포기하고 풀이 검색을 해봤는데 정말 상상도 못할 방법으로 푼 해답을 발견했다. 아니… 대체 왜 이렇게 되는거냐고;;; 이런거 짜는 사람들은 대체 누굴까..;; https://www.geeksforgeeks.org/longest-common-subsequence-dp-4/ static int commonChild(string s1, string s2) { char[] X = s1.ToC..

프로그래밍 2023.02.20

[HackerRank] Sparse Arrays

2019-05-28 글쓴이 TED HONG [HackerRank] Sparse Arrays 오늘 문제는 너무 기초네..;;; 주어진 배열안에 검색어가 몇 개인지 찾는 문제..;; static int[] matchingStrings(string[] strings, string[] queries) { List result = new List(); foreach(string q in queries) { result.Add(GetContainsCount(strings, q)); } return result.ToArray(); } static int GetContainsCount(string[] arr, string q) { List list = new List(arr); int result = list.Coun..

프로그래밍 2023.02.20

[Hackerrank] Left Rotation

2019-05-27 글쓴이 TED HONG [Hackerrank] Left Rotation 배열 a 중에 특정한 숫자 n을 지정한 횟수 d 만큼 왼쪽으로 로테이션 시키는 문제 class Solution { static void Main(string[] args) { string[] nd = Console.ReadLine().Split(' '); int n = Convert.ToInt32(nd[0]); int d = Convert.ToInt32(nd[1]); int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), aTemp => Convert.ToInt32(aTemp)) ; int[] result = GetRotateArray(n, d, a); Console..

프로그래밍 2023.02.20

[HackerRank] Sherlock and Anagrams

2019-05-22 글쓴이 TED HONG [HackerRank] Sherlock and Anagrams 문자열내의 Anagram 쌍이 몇개인지 찾는 문제 단어를 잘라서 Lowercase 로 변환, 정렬 후 Dictionary 에 (단어, 갯수) 로 넣어서 계산하는 방식도 될 거 같은데 일단 무식한 방법으로 풀어봤다. 3중for문이라 인풋값에 긴 문자열이 들어오면 타임아웃이 뜬다;;; static int sherlockAndAnagrams(string s) { int result = 0; for (int i = 1; i < s.Length + 1; i++) //i 는 단어의 길이 점점 늘어남 { List words = new List(); for (int j = 0; j < s.Length - (i -1..

프로그래밍 2023.02.20

[HackerRank] New Year Chaos

2019-05-22 글쓴이 TED HONG [HackerRank] New Year Chaos 줄을 서있는데 뒷사람이 앞사람에게 뇌물을 주고 자리를 바꿀 수 있음 한 사람당 2회 가능. 주어진 순서가 되려면 몇번 뇌물이 오고갔는가? 헷갈리네. ㅠ static void minimumBribes(int[] q) { const int bribePower = 2; bool isChaotic = false; int n = q.Length; for (int i = 0; i bribePower) { Console.WriteLine("Too chaotic"); isChaotic = true; break; } } int bribeCount = 0; if (isChaotic == false) { for (int i = 0;..

프로그래밍 2023.02.20

[Hackerrank] 2D Array – DS

2019-05-20 글쓴이 TED HONG [Hackerrank] 2D Array – DS 2중 배열안에서 모래시계 모양의 패턴을 찾아 해당 좌표의 값을 모두 더했을 때 가장 큰 값을 찾는 문제 음수 비교가 필요한 경우가 있으므로 결과값 변수를 int.MinValue로 초기화 한다. static int hourglassSum(int[][] arr) { int result = int.MinValue; int row = arr.Length; for (int i = 0; i < row -2; i++) { int col = arr[i].Length; for (int j = 0; j < col -2; j++) { int sum = arr[i][j] + arr[i][j + 1] + arr[i][j + 2]; sum..

프로그래밍 2023.02.20

[Hackerrank] Repeated String

2019-05-20 글쓴이 TED HONG [Hackerrank] Repeated String 인풋값은 두가지 반복 할 문자열, 문자열의 총 길이. 문자열의 총 길이만큼 문자열을 반복한 후에 전체 문자열에 포함된 a 의 갯수를 구하는 문제. static long repeatedString(string s, long n) { long result = 0; long strLength = s.Length; var cntStr = new System.Text.RegularExpressions.Regex("a"); long aCount = cntStr.Matches(s).Count; long q = n / strLength; long r = n % strLength; result = q * aCount; if(r..

프로그래밍 2023.02.20