查找

xiaoxiao2021-02-28  127

package com.Main.dl; import java.util.*; public class BinarySearch { public static int getPos(int[] A, int n, int val) { // write code here //初始值 int low=0; int high=A.length-1; int bijiaozhi=0; //第一次比较 while(val!=A[bijiaozhi]){ bijiaozhi=(low+high)/2; if(val<A[bijiaozhi]){ high=bijiaozhi-1; }else{ low=bijiaozhi+1; } } return bijiaozhi; } public static void main(String[] args){ int[] src={1,3,5,7,9}; int len=5; int destvalue=3; int returnvalue=getPos(src,len,destvalue); System.out.println(returnvalue); } } import java.util.*; public class FirstRepeat { public char findFirstRepeat(String A, int n) { // write code here for(int i=1;i<n;i++){ for(int j=i-1;j>=0;j--){ if(A.charAt(i)==A.charAt(j)) return A.charAt(j); } } return '0'; } }
转载请注明原文地址: https://www.6miu.com/read-63941.html

最新回复(0)