首页 > 其他 > 详细

LeetCode - 刷题经验

时间:2019-03-20 17:06:58      阅读:140      评论:0      收藏:0      [点我收藏+]

1、加快代码速度

  刷了前面几道题发现速度总是处于尾部10%,刚开始非常不服,后来仔细一看那些排名靠前的提交,发现了猫腻。几乎每一个提交都有这样的一段代码:

static const auto io_sync_off = []()
{
    // turn off sync
    std::ios::sync_with_stdio(false);
    // untie in/out streams
    std::cin.tie(nullptr);
    return nullptr;
}();

  啥意思?看拆分的这几部分解析:

  (1)网友写的《C++11 Lambda表达式

  (2)另一位网友写的代码分析:https://blog.csdn.net/qq_32320399/article/details/81518476

  简单来说就是取消了 std::cin 与 stdin的同步, 又解除了默认std::cin与std::cout 绑定。这两个操作使得数据输入的速度大幅提升,从而节省了整体的运行时间。

LeetCode - 刷题经验

原文:https://www.cnblogs.com/kuliuheng/p/10565997.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!