当前位置: 首页>>代码示例>>C++>>正文


C++ Answer::maxSlidingWindow方法代码示例

本文整理汇总了C++中Answer::maxSlidingWindow方法的典型用法代码示例。如果您正苦于以下问题:C++ Answer::maxSlidingWindow方法的具体用法?C++ Answer::maxSlidingWindow怎么用?C++ Answer::maxSlidingWindow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Answer的用法示例。


在下文中一共展示了Answer::maxSlidingWindow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char* argv[]) {
  Test test;
  Solution sol;
  Answer ans;
  chrono::time_point<chrono::system_clock> ts0, ts1, ts2, ts3, ts4;
  ofstream outfile;
  outfile.open("output.txt");

  ts0 = std::chrono::system_clock::now();
  vector<int> tin = test.generate();

  ts1 = std::chrono::system_clock::now();
  vector<int> touts = sol.maxSlidingWindow(tin, TK);

  ts2 = std::chrono::system_clock::now();
  vector<int> touta = ans.maxSlidingWindow(tin, TK);

  ts3 = std::chrono::system_clock::now();
  if (touts.size() != touta.size()) {
    cout << "Error, solution size not equal" << endl;
    return -1;
  } else {
    for(int i=0; i<touts.size(); i++) {
      if (touts[i] != touta[i]) {
        cout << "Error, solution vector item: " << i << " not equal" << endl;
        return -2;
      } else {
        outfile << touts[i] << endl;
      }
    }
  }
  ts4 = std::chrono::system_clock::now();
  chrono::duration<double> e10 = ts1-ts0;
  chrono::duration<double> e21 = ts2-ts1;
  chrono::duration<double> e32 = ts3-ts2;
  chrono::duration<double> e43 = ts4-ts3;
  cout << argv[0] << " All test passed ~" << endl;
  cout << argv[0] << " Elapsed time generate test case:   " << e10.count() << endl;
  cout << argv[0] << " Elapsed time my solution O(N):     " << e21.count() << endl;
  cout << argv[0] << " Elapsed time official O(N) answer: " << e32.count() << endl;
  cout << argv[0] << " Elapsed time comparison result:    " << e43.count() << endl;

  outfile.close();
  return 0;
}
开发者ID:baiyz,项目名称:leetcode,代码行数:45,代码来源:lc239.cpp


注:本文中的Answer::maxSlidingWindow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。