leetcode笔记
- string 和 int 相互转换:
int 转 string:string str = to_string(number);
string 转 int:int number = stoi(str.c_str());
使用时要注意stoi
函数中参数str
不能为空字符串,字符串也不能过大,需要能转换为 int 类型 - max 函数,定义与
中,可接受 两个参数 或 一个 initializer_list 对象:
cout << max(1,2) << endl;
initializer_list<int> ini = {1,2,4,5,-1};
cout << max(ini) << endl;
-
c++ 各类型最大最小值宏定义:
头文件:#include <climits>
INT_MAX,INT_MIN,UINT_MAX,LONG_MAX,LONG_MIN,ULONG_MAX,LLONG_MAX,LLONG_MIN,ULLONG_MAX
c++各类型最大最小值宏定义 -
使用 string::find(),返回找到的第一个下标。如果没找到,返回 string::npos (leetcode 1143.)
-
pair 结构体在
#include <utility>
中 -
#include<bits/stdc++.h>
包含所有的头文件 -
一些关于字符串操作的函数:
strchr
,strrchr
,strpbrk
,strspn
-
dp 中背包问题首先考虑的递归公式推法是:如果容量为 j 的背包装得下/装不下 nums[i]