public class Solution { public int SearchInsert(int[] nums, int target) { if (nums.Contains(target)) { return Array.IndexOf(nums, target); } else { return zhong(nums,0,nums.Length-1,target); } } private int zhong(int[] ss,int start,int end,int target) { if (target < ss[end] && target > ss[start]) { if (ss[(int)((start + end) / 2)] < target && target < ss[(int)((start + end) / 2) + 1]) { return (int)((start + end) / 2) + 1; } else { if(ss[(int)((start + end) / 2)] > target) { return zhong(ss, start, (int)((start + end) / 2),target); } else { return zhong(ss, (int)((start + end) / 2),end , target); } } } else { if (target < ss[start]) { return start; } else { return end+1; } } } }
C#代码,望大神指正
原文:https://www.cnblogs.com/jianghaidong/p/10369675.html