归档

STL之map,multimap

  • 头文件及声明
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #include <map>

    namespace std
    {
    template <typename Key, typename T,
    typename Compare = less<key>,
    typename Allocator = allocator<pair<const Key, T>>>
    class map;

    template <typename Key, typename T,
    typename Compare = less<key>,
    typename Allocator = allocator<pair<const Key, T>>>
    class multimap;
    }

leetcode第5题

5.Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.

题目大意就是求出一个字符串的最大回文子串,思路借鉴了讨论区中的某位同学,就是用两个标记依次往两头延伸,如给定a,b,判断s[a-1]与s[b+1]是否相等,若相等则–a, ++b在进行判断,直到不等为止,得出maxlen=b-a+1,代码运行时间4ms。代码如下:

STL之list

  • 头文件及声明
    1
    2
    3
    4
    5
    6
    #include <list>
    namespace std
    {
    template <typename T, typename Allocator = allocator<T>>
    class list;
    }

STL之forward_list

  • 头文件及声明
    1
    2
    3
    4
    5
    6
    7
    8
    9
    /*
    C++11
    */

    #include <forward_list>
    namespace std
    {
    template <typename T, typename Allocator = allocator<T>>
    class forward_list;
    }

STL之deque

  • 头文件及声明
    1
    2
    3
    4
    5
    6
    7
    8
    #include <deque>
    namespace std
    {
    template <typename T, typename Allocator = allocator<T>>
    class deque;
    }

    <!--more-->

deque可以在头尾进行快速的插入,其他操作类似与vector。但其实现确实较为复杂,有关其实现详见csdn博客