Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am shun2439 on github.
  • I am shun2439 (https://keybase.io/shun2439) on keybase.
  • I have a public key ASBl3TWWPRasZA6GtF80mKWOus9fVgKFqsmCd8xHltrwRAo

To claim this, I am signing this object:

@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 の左端と右端