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