leetcode笔记

  1. string 和 int 相互转换:
    int 转 string:string str = to_string(number);
    string 转 int:int number = stoi(str.c_str());
    使用时要注意stoi函数中参数str不能为空字符串,字符串也不能过大,需要能转换为 int 类型
  2. max 函数,定义与 中,可接受 两个参数 或 一个 initializer_list 对象:
    cout << max(1,2) << endl;
    initializer_list<int> ini = {1,2,4,5,-1};
    cout << max(ini) << endl;
  1. c++ 各类型最大最小值宏定义:
    头文件:#include <climits>
    INT_MAX,INT_MIN,UINT_MAX,LONG_MAX,LONG_MIN,ULONG_MAX,LLONG_MAX,LLONG_MIN,ULLONG_MAX
    c++各类型最大最小值宏定义

  2. 使用 string::find(),返回找到的第一个下标。如果没找到,返回 string::npos (leetcode 1143.)

  3. pair 结构体在 #include <utility>

  4. #include<bits/stdc++.h> 包含所有的头文件

  5. 一些关于字符串操作的函数:strchr,strrchr,strpbrk,strspn

  6. dp 中背包问题首先考虑的递归公式推法是:如果容量为 j 的背包装得下/装不下 nums[i]

posted @ 2023-02-04 19:18  SanFranciscoo  阅读(14)  评论(0编辑  收藏  举报