算法
未读
常用代码模板2——数据结构
单链表 // head存储链表头,e[]存储节点的值,ne[]存储节点的next指针,idx表示当前用到了哪个节点
int head, e[N], ne[N], idx;
// 初始化
void init()
{
head = -1;
idx = 0;
}
// 在链表头插入一个
算法
未读
常用代码模板1——基础算法
快速排序算法模板 void quick_sort(int q[], int l, int r)
{
if (l >= r) return;
int i = l - 1, j = r + 1, x = q[(l + r) >> 1];
while (i < j)
{
算法
未读
LeetCode 70 爬楼梯(青蛙跳台阶)
假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数。 示例 1: 输入: 2
输出: 2
解释: 有两种方法可以爬到楼顶。
1. 1 阶 + 1 阶
2. 2 阶
示例 2: 输入: 3
输出:
算法
未读
LeetCode 398 随机数索引
给定一个可能含有重复元素的整数数组,要求随机输出给定的数字的索引。 您可以假设给定的数字一定存在于数组中。 注意: 数组大小可能非常大。 使用太多额外空间的解决方案将不会通过测试。 示例: int[] nums = new int[] {1,2,3,3,3};
Solution solution =
算法
未读
LeetCode 486 Predict the Winner(预测赢家)
题目 给定一个表示分数的非负整数数组。 玩家 1 从数组任意一端拿取一个分数,随后玩家 2 继续从剩余数组任意一端拿取分数,然后玩家 1 拿,…… 。每次一个玩家只能拿取一个分数,分数被拿取之后不再可取。直到没有剩余分数可取时游戏结束。最终获得分数总和最多的玩家获胜。 给定一个表示分数的数组,预测玩
算法
未读
LeetCode 6 ZigZag Conversion(Z字转换)
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font
算法
未读
LeetCode 106 Construct Binary Tree from Inorder and Postorder Traversal(由中序和后序遍历建立二叉树)
Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. For example
算法
未读
LeetCode 5 Longest Palindromic Substring(最长回文字串)
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Input: "babad"
Output:
算法
未读
LeetCode 8 String to Integer (atoi)
Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-white
算法
未读
数据结构与算法解析习题2.23
数据结构与算法解析习题2.23:实现对分查找使得在每次迭代中只有一个二路比较 这个题目说每次迭代只有一个二路比较不太明确是什么意思,我觉得应该是只比较一次吧,那就把判断mid的逻辑放在迭代之后了。 也不知道这么理解对不对,希望有明白人给解解惑。。
#include <stdio.h>
int