mirror of
https://github.com/krahets/hello-algo.git
synced 2025-01-23 22:40:25 +08:00
fix(docs/cpp): fix error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare]
This commit is contained in:
parent
e318c495f7
commit
5cc58c7b91
@ -48,8 +48,8 @@ int main() {
|
||||
PrintUtil::printVector(list);
|
||||
|
||||
/* 通过索引遍历列表 */
|
||||
int count = 0;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
size_t count = 0;
|
||||
for (size_t i = 0; i < list.size(); i++) {
|
||||
count++;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ vector<int> randomNumbers(int n) {
|
||||
|
||||
/* 查找数组 nums 中数字 1 所在索引 */
|
||||
int findOne(vector<int>& nums) {
|
||||
for (int i = 0; i < nums.size(); i++) {
|
||||
for (size_t i = 0; i < nums.size(); i++) {
|
||||
if (nums[i] == 1)
|
||||
return i;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ int main() {
|
||||
vector<int> nums = { 1, 5, 3, 2, 4, 7, 5, 9, 10, 8 };
|
||||
// 初始化哈希表
|
||||
unordered_map<int, int> map;
|
||||
for (int i = 0; i < nums.size(); i++) {
|
||||
for (size_t i = 0; i < nums.size(); i++) {
|
||||
map[nums[i]] = i; // key: 元素,value: 索引
|
||||
}
|
||||
int index = hashingSearch(map, target);
|
||||
|
@ -9,7 +9,7 @@
|
||||
/* 线性查找(数组) */
|
||||
int linearSearch(vector<int>& nums, int target) {
|
||||
// 遍历数组
|
||||
for (int i = 0; i < nums.size(); i++) {
|
||||
for (size_t i = 0; i < nums.size(); i++) {
|
||||
// 找到目标元素,返回其索引
|
||||
if (nums[i] == target)
|
||||
return i;
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
vector<int> toVector() {
|
||||
ListNode* node = front;
|
||||
vector<int> res(size());
|
||||
for (int i = 0; i < res.size(); i++) {
|
||||
for (size_t i = 0; i < res.size(); i++) {
|
||||
res[i] = node->val;
|
||||
node = node->next;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user