Problem solving 40

[LeetCode] 35. Search Insert Position (C#)

LeetCode - Problems - Algorithms - 35. Search Insert Position Problem Description Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. My Solution (C#) nums에 target을 insert한다고 가정 했을 때, insert 되는 위치를 return하는 문제. nums는 오름차순으로 정렬되어있고, target 또한 오름차순에 맞게 insert 되어야 한다는 조건이 있다. ..

[LeetCode] 28. Implement strStr() (C#)

LeetCode - Problems - Algorithms - 28. Implement strStr() Problem Description My Solution (C#) 변수 이름에서 알 수 있듯이, 주어진 string 건초더미에서 string 바늘이 있는지 찾는 문제이다. C#의 IndexOf (C의 경우는 StrStr)를 구현하는 문제다. Description을 끝까지 안읽어서 (끝까지 읽읍시다...) IndexOf를 사용해서 풀었다. (??) // Implementing IndexOf by using IndexOf (???) public class Solution { public int StrStr(string haystack, string needle) { if (string.IsNullOrEmp..

[LeetCode] 26. Remove Duplicates from Sorted Array (C#)

LeetCode - Problems - Algorithms - 26. Remove Duplicates from Sorted Array Problem Description My Solution (C#) public class Solution { public int RemoveDuplicates(int[] nums) { if (nums.Length == 0) return 0; int index = 0; for (int i = 1; i < nums.Length; i++) { if (nums[index] != nums[i]) { nums[++index] = nums[i]; } } return ++index; } } C#의 regular array는 길이를 조절할 수 없는 array이다. 그러다 문제는 array..