File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -760,8 +760,56 @@ object Solution {
760
760
}
761
761
}
762
762
```
763
+ ** Dart:**
763
764
764
765
766
+
767
+ ``` dart
768
+ (版本一)左闭右闭区间
769
+ class Solution {
770
+ int search(List<int> nums, int target) {
771
+ int left = 0;
772
+ int right = nums.length - 1;
773
+ while (left <= right) {
774
+ int middle = ((left + right)/2).truncate();
775
+ switch (nums[middle].compareTo(target)) {
776
+ case 1:
777
+ right = middle - 1;
778
+ continue;
779
+ case -1:
780
+ left = middle + 1;
781
+ continue;
782
+ default:
783
+ return middle;
784
+ }
785
+ }
786
+ return -1;
787
+ }
788
+ }
789
+
790
+ (版本二)左闭右开区间
791
+ class Solution {
792
+ int search(List<int> nums, int target) {
793
+ int left = 0;
794
+ int right = nums.length;
795
+ while (left < right) {
796
+ int middle = left + ((right - left) >> 1);
797
+ switch (nums[middle].compareTo(target)) {
798
+ case 1:
799
+ right = middle;
800
+ continue;
801
+ case -1:
802
+ left = middle + 1;
803
+ continue;
804
+ default:
805
+ return middle;
806
+ }
807
+ }
808
+ return -1;
809
+ }
810
+ }
811
+ ```
812
+
765
813
<p align =" center " >
766
814
<a href =" https://programmercarl.com/other/kstar.html " target =" _blank " >
767
815
<img src =" ../pics/网站星球宣传海报.jpg " width =" 1000 " />
You can’t perform that action at this time.
0 commit comments