This commit is contained in:
krahets
2023-02-08 04:17:26 +08:00
parent 7f4efa6d5e
commit 0407cc720c
347 changed files with 150 additions and 132904 deletions
+2 -23
View File
@@ -21,17 +21,7 @@ comments: true
=== "C++"
```cpp title="linear_search.cpp"
/* 线性查找(数组) */
int linearSearchArray(vector<int>& nums, int target) {
// 遍历数组
for (int i = 0; i < nums.size(); i++) {
// 找到目标元素,返回其索引
if (nums[i] == target)
return i;
}
// 未找到目标元素,返回 -1
return -1;
}
[class]{}-[func]{linearSearchArray}
```
=== "Python"
@@ -151,18 +141,7 @@ comments: true
=== "C++"
```cpp title="linear_search.cpp"
/* 线性查找(链表) */
ListNode* linearSearchLinkedList(ListNode* head, int target) {
// 遍历链表
while (head != nullptr) {
// 找到目标结点,返回之
if (head->val == target)
return head;
head = head->next;
}
// 未找到目标结点,返回 nullptr
return nullptr;
}
[class]{}-[func]{linearSearchLinkedList}
```
=== "Python"