美文网首页
Leetcode[646] Maximum Length of

Leetcode[646] Maximum Length of

作者: 耳可黄 | 来源:发表于2017-08-25 02:47 被阅读0次
Algorithm
  • Uses greedy algorithm: want to start with the pair with the smallest tail number (so we can have the most room for the following chain)
  • Requires sorting
知识点
  • sort c++ vector
    use std::sort(RandomAcessIterator begin, RandomAcessIterator end, Compare comp)
    need to define function for comp
class myClass {
  static bool comp (T a, T b) { //statement }
  void foo() { 
    //statement
    sort(myVector.begin(), myVector.end(), comp);
    //statement
  }
}

or

book comp (T a, T b) { //statement }
class myClass {
  //same
}

需注意在class内define的comp前要加static关键词

相关文章

网友评论

      本文标题:Leetcode[646] Maximum Length of

      本文链接:https://www.haomeiwen.com/subject/bdiydxtx.html