[내일 배움 캠프 Unity 4기] W7D2 05.28 TIL

김용준·2024년 5월 28일
0

내일배움캠프

목록 보기
22/47

Goals

  • Try to solve algorithm problem
  • Learn Unity feature; Camera

Algorithm from programmers.com

The basic level problem contains the variation of array with sorting / dividing. With the knowledge of C# and other programming skills, I could write the answer of problem. What I solved on today could be summarized with the list.

  • Cut the array until the element n;
  • Cut the array from the element n;
  • Find the first index when negative value appears;
  • Make count-down array of input n,k;

By using the for, List and some logics, I could write the answer like that.

int[] Solution(int[] input_arr, int n)
{
	for(...)
    {
    	...
    }
}

After submitting my own answer, the other solutions can be seen. Using the features of array, there were more compact, easier to understand methods.

The one of those method is the function of array.

int[] result = new int[<number of array>];
Array.Copy(<src array>, <starting idx or src>, <destination>, <starting idx of destination>,<number>);

Facilitating the Array.Copy method makes my understand easier. Keeping that on my TIL, I faced the other problems.

There is other cases which invokes Array in the solution with lamda equation.
In the problem that requires the index of negative element, the simple answer is

Array.FindIndex(<input array>,f => f<0)

Which use the application of anomynous method f => f<0. We can understand the operation. searching the element one by one, and check the negative.

Finally, I have learned the convertion to use the method in List. The problem asks us to make array starting from the index of mediator.

<input_array>.Skip(n - 1).ToArray();

The solution say that It will skip the first several element and make it to new array.

Review

I have to learn more about the intrinsic methods.

profile
꿈이큰개발자지망생

0개의 댓글