public class TodayDeal {
static void main(String[] args) {
Map<String, String> map = new HashMap<>()
map.put("code","1")
Map<String, String> map1 = new HashMap<>()
map1.put("code","2")
Map<String, String> map2 = new HashMap<>()
map2.put("code","3")
List<Map<String, String>> list = new ArrayList<>()
list.add(map)
list.add(map1)
list.add(map2)
boolean a = getValue(list, 0, list.size() - 1, "2")
}
//list里面的内容从小到大排序,返回true表示存在,false表示不存在,map
static boolean getValue(List<Map<String, String>> list, int start, int end, String value) {
int middle = ((int) ((end - start) % 2 == 1 ? ((end - start) / 2 + 1) : (end - start) / 2)) + start
String com = list.get(middle).get("code")
if (com == value) {
return true
} else if (value < com && start != end) {
return getBondValue(list, start, middle - 1 >= start ? middle - 1 : middle, value)
} else if (value > com && start != end) {
return getBondValue(list, middle + 1 <= end ? middle + 1 : middle, end, value)
}
return false
}
//list里面的内容从小到大排序,返回true表示存在,false表示不存在,String
static boolean getValue(List<String> list, int start, int end, String value) {
int middle = ((int) ((end - start) % 2 == 1 ? ((end - start) / 2 + 1) : (end - start) / 2)) + start
String com = list.get(middle)
if (com == value) {
return true
} else if (value < com && start != end) {
return getBondValue(list, start, middle - 1 >= start ? middle - 1 : middle, value)
} else if (value > com && start != end) {
return getBondValue(list, middle + 1 <= end ? middle + 1 : middle, end, value)
}
return false
}
}