Skip to content

Instantly share code, notes, and snippets.

@Shun2439
Shun2439 / bin_search.cpp
Last active December 18, 2023 07:36
garbages
#include <iostream>
#include <vector>
using namespace std;
vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
// 目的の値 key の index を返すようにする (ない場合は -1)
int binary_search(int key)
{
int left = 0, right = (int)a.size() - 1; // 配列 a の左端と右端