算法
码上起飞
这个作者很懒,什么都没留下…
展开
-
Leetcode 852. 山脉数组的峰顶索引
文章目录题目链接代码二分枚举暴力枚举题目链接852. 山脉数组的峰顶索引代码二分枚举int peakIndexInMountainArray(int* arr, int arrSize){ int l = 1, r = arrSize - 2, mid, ret; while (l <= r) { mid = l + (r - l >> 1); // 1 if (arr[mid] > arr[mid + 1]) {原创 2022-04-12 02:49:10 · 386 阅读 · 0 评论 -
Leetcode 744. 寻找比目标字母大的最小字母
文章目录题目链接代码二分查找题目链接744. 寻找比目标字母大的最小字母代码二分查找char nextGreatestLetter(char* letters, int lettersSize, char target){ int left = 0, right = lettersSize - 1; int ans = 0; // 1 while (left <= right) { int mid = left + right >> 1;原创 2022-04-11 00:30:06 · 497 阅读 · 0 评论 -
Leetcode 167. 两数之和 II - 输入有序数组
文章目录题目链接代码法一 暴力枚举超时法二 二分查找题目链接167. 两数之和 II - 输入有序数组代码法一 暴力枚举超时/** * Note: The returned array must be malloced, assume caller calls free(). */int* twoSum(int* numbers, int numbersSize, int target, int* returnSize){ int *ret = (int*)malloc(sizeof原创 2022-04-10 23:07:15 · 330 阅读 · 0 评论 -
Leetcode 374. 猜数字大小
文章目录题目链接代码法一 暴力枚举超时法二 二分查找题目链接374. 猜数字大小代码法一 暴力枚举超时/** * Forward declaration of guess API. * @param num your guess * @return -1 if num is lower than the guess number * 1 if num is higher than the guess number * oth原创 2022-04-10 22:58:43 · 220 阅读 · 0 评论 -
Leetcode 704. 二分查找
文章目录题目链接代码法一 暴力枚举法二 二分查找题目链接704. 二分查找代码法一 暴力枚举int search(int* nums, int numsSize, int target){ for (int i = 0; i < numsSize; ++i) { if (target == nums[i]) return i; } return -1;}法二 二分查找int search(int* nums, int n原创 2022-04-10 22:46:21 · 177 阅读 · 0 评论 -
Depth-First Search(深度优先搜索)
This search algorithm is specially designed for graphs and trees.As you may recall, a Graph is a set of connected nodes where each node is called a vertex and the connection between two of them is called an edge. While a tree is basically the same with t原创 2022-03-14 10:32:28 · 1290 阅读 · 0 评论