본문 바로가기

공부하자/Codility

(35)
[Codility] Lesson9. MaxSliceSum (C#) 문제: app.codility.com/programmers/lessons/9-maximum_slice_problem/max_slice_sum/ MaxSliceSum coding task - Learn to Code - Codility Find a maximum sum of a compact subsequence of array elements. app.codility.com 결과: 84% 다시풀기.. if (A.Length < 1) return 0; int max = A[0]; int index = A[0]; for (int i = 1; i < A.Length; i++) { index += A[i]; if (max < index) max = index; if (max < A[i]) { max = A[i]..
[Codility] Lesson9. MaxProfit (C#) 문제: app.codility.com/programmers/lessons/9-maximum_slice_problem/max_profit/ MaxProfit coding task - Learn to Code - Codility Given a log of stock prices compute the maximum possible earning. app.codility.com if (A.Length A[i]) minValue = A[i]; } if (maxProfit < 0) return 0; return maxProfit;
[Codility] Lesson9. MaxDoubleSliceSum (C#) 문제: app.codility.com/programmers/lessons/9-maximum_slice_problem/max_double_slice_sum/ MaxDoubleSliceSum coding task - Learn to Code - Codility Find the maximal sum of any double slice. app.codility.com 결과: 84% 다시 풀어야 함. if (A.Length A[i]) { min = A[i]; } temp -= A[i]; if (temp == 0) { minpos = i; break; } } if (min > 0 && (maxpos = 2)) { return postMaxSum; } return postMaxSum - min;
[Codility] Lesson8. EquiLeader (C#) 문제: app.codility.com/programmers/lessons/8-leader/equi_leader/ EquiLeader coding task - Learn to Code - Codility Find the index S such that the leaders of the sequences A[0], A[1], ..., A[S] and A[S + 1], A[S + 2], ..., A[N - 1] are the same. app.codility.com 결과: 88% 다시 풀어야 함.. 하아.. 언제 풀려나..ㅠ Dictionary dic = new Dictionary(); int max = 0; int index = 0; int result = 0; int count = 0; for (int i..
[Codility] Lesson8. Dominator (C#) 문제: app.codility.com/programmers/lessons/8-leader/dominator/ Dominator coding task - Learn to Code - Codility Find an index of an array such that its value occurs at more than half of indices in the array. app.codility.com 결과: 91% 다시 풀어야 함. if (A.Length == 0) return -1; else if (A.Length == 1) return 0; Dictionary dic = new Dictionary(); for (int i = 0; i < A.Length; i++) { if (dic.ContainsKey(A..
[Codility] Lesson7. StoneWall (C#) 문제: app.codility.com/programmers/lessons/7-stacks_and_queues/stone_wall/ StoneWall coding task - Learn to Code - Codility Cover "Manhattan skyline" using the minimum number of rectangles. app.codility.com Stack stack = new Stack(); int result = 0; for (int i = 0; i 0) { if (stack.Peek() == H[i]) { stack.Pop();..
[Codility] Lesson7. Nesting (C#) 문제: app.codility.com/programmers/lessons/7-stacks_and_queues/nesting/ Nesting coding task - Learn to Code - Codility Determine whether a given string of parentheses (single type) is properly nested. app.codility.com List listS = new List(S); Stack stackS = new Stack(); for (int i = 0; i 0) { if (stac..
[Codility] Lesson7. Fish (C#) 문제: app.codility.com/programmers/lessons/7-stacks_and_queues/fish/ Fish coding task - Learn to Code - Codility N voracious fish are moving along a river. Calculate how many fish are alive. app.codility.com Stack up = new Stack(); Stack down = new Stack(); for (int i = 0; i 0) { if (down.Peek() < A[..