File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -561,5 +561,51 @@ class Solution {
561561}
562562```
563563
564+ ** C#:**
565+ ``` csharp
566+ // 左闭右闭
567+ public class Solution {
568+ public int Search (int [] nums , int target ) {
569+ int left = 0 ;
570+ int right = nums .Length - 1 ;
571+ while (left <= right ){
572+ int mid = (right - left ) / 2 + left ;
573+ if (nums [mid ] == target ){
574+ return mid ;
575+ }
576+ else if (nums [mid ] < target ){
577+ left = mid + 1 ;
578+ }
579+ else if (nums [mid ] > target ){
580+ right = mid - 1 ;
581+ }
582+ }
583+ return - 1 ;
584+ }
585+ }
586+
587+ // 左闭右开
588+ public class Solution {
589+ public int Search (int [] nums , int target ){
590+ int left = 0 ;
591+ int right = nums .Length ;
592+ while (left < right ){
593+ int mid = (right - left ) / 2 + left ;
594+ if (nums [mid ] == target ){
595+ return mid ;
596+ }
597+ else if (nums [mid ] < target ){
598+ left = mid + 1 ;
599+ }
600+ else if (nums [mid ] > target ){
601+ right = mid ;
602+ }
603+ }
604+ return - 1 ;
605+ }
606+ }
607+ ```
608+
609+
564610-----------------------
565611<div align =" center " ><img src =https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width =500 > </img ></div >
You can’t perform that action at this time.
0 commit comments