
数组
长夜qingfeng
羽落尽长安,南亭风林晚
展开
-
HDU Number Sequence
题目Problem DescriptionA number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n).InputThe input consists of multiple test cases. Each test case conta原创 2021-03-14 10:10:50 · 122 阅读 · 0 评论 -
HDU 1239 Calling Extraterrestrial Intelligence Again
题目http://acm.hdu.edu.cn/showproblem.php?pid=1239Problem DescriptionA message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November 16, 1974. The message consisted o原创 2021-03-08 21:54:23 · 590 阅读 · 0 评论 -
各种排序方法汇总
还是以前老师上课总结的//经典排序算法: 冒泡、选择、插入、希尔、快排、归并#include<stdio.h>#include<stdlib.h>void swap0(int *a, int *b){ int temp = *a; *a = *b; *b = temp;}//交换数组a[]中的第i和第j个元素void swap(int *a, int i, int j){ int temp = a[i]; a[i] = a[j];原创 2021-03-08 20:24:00 · 238 阅读 · 0 评论 -
leetcode--167. 两数之和 II - 输入有序数组
题目链接https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/一、题目给定一个已按照 升序排列 的整数数组 numbers ,请你从数组中找出两个数满足相加之和等于目标数 target 。函数应该以长度为 2 的整数数组的形式返回这两个数的下标值。numbers 的下标 从 1 开始计数 ,所以答案数组应当满足 1 <= answer[0] < answer[1] <= numbers.length 。原创 2021-02-17 21:25:54 · 115 阅读 · 0 评论 -
leetcode--122. 买卖股票的最佳时机 II
题目链接https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/一、题目给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。示例 1:输入: [7,1,5,3,6,4]输出: 7解释: 在第 2 天(股票价格 = 1)的时候买入,在第 3 天(原创 2021-02-06 15:59:16 · 186 阅读 · 0 评论 -
leetcode--119. 杨辉三角 II
题目链接https://leetcode-cn.com/problems/pascals-triangle-ii/一、题目给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。在杨辉三角中,每个数是它左上方和右上方的数的和。示例:输入: 3输出: [1,3,3,1]二、分析与代码1.代码如下(示例):/** * Note: The returned array must be malloced, assume caller calls free(). */int*原创 2021-02-06 15:01:30 · 176 阅读 · 0 评论 -
POJ Bull Math(大数相乘,高精度乘法)
前言用此例题来记录下高精度乘法一、分析既然涉及到高精度必然是用数组来解决了二、代码1.代码如下(示例):#include<stdio.h>#include<string.h>#include<stdlib.h>#define maxn 45char s1[maxn],s2[maxn];int ss[2*maxn];void mul(char* a,char* b,int* c){ int i,j,len1,len2,*s; le原创 2021-01-29 21:46:40 · 177 阅读 · 2 评论 -
leetcode--118. 杨辉三角
题目链接https://leetcode-cn.com/problems/pascals-triangle/一、题目给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。在杨辉三角中,每个数是它左上方和右上方的数的和。示例:输入: 5输出:[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]二、代码代码如下(示例):/** * Return an array of arrays of size *returnSize. *原创 2021-01-28 22:16:41 · 144 阅读 · 0 评论 -
leetcode--67. 二进制求和
题目链接https://leetcode-cn.com/problems/add-binary/一、题目给你两个二进制字符串,返回它们的和(用二进制表示)。输入为 非空 字符串且只包含数字 1 和 0。示例 1:输入: a = “11”, b = “1”输出: “100”示例 2:输入: a = “1010”, b = “1011”输出: “10101”提示:每个字符串仅由字符 ‘0’ 或 ‘1’ 组成。1 <= a.length, b.length <= 10^4字原创 2021-01-25 10:19:26 · 86 阅读 · 0 评论 -
leetcode--38. 外观数列
题目链接https://leetcode-cn.com/problems/count-and-say/一、题目给定一个正整数 n ,输出外观数列的第 n 项。「外观数列」是一个整数序列,从数字 1 开始,序列中的每一项都是对前一项的描述。你可以将其视作是由递归公式定义的数字字符串序列:countAndSay(1) = “1”countAndSay(n) 是对 countAndSay(n-1) 的描述,然后转换成另一个数字字符串。前五项如下:111211211原创 2021-01-24 21:14:31 · 153 阅读 · 1 评论 -
leetcode--20. 有效的括号
题目链接https://leetcode-cn.com/problems/valid-parentheses/一、题目给定一个只包括 ‘(’,’)’,’{’,’}’,’[’,’]’ 的字符串,判断字符串是否有效。有效字符串需满足:左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序闭合。注意空字符串可被认为是有效字符串。示例 1:输入: “()”输出: true示例 2:输入: “()[]{}”输出: true示例 3:输入: “(]”输出: false示例 4:输入原创 2021-01-24 17:41:44 · 97 阅读 · 0 评论 -
leetcode--14. 最长公共前缀
题目链接https://leetcode-cn.com/problems/longest-common-prefix/一、题目编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串 “”。示例 1:输入:strs = [“flower”,“flow”,“flight”]输出:“fl”示例 2:输入:strs = [“dog”,“racecar”,“car”]输出:""解释:输入不存在公共前缀。提示:0 <= strs.length <= 200原创 2021-01-24 17:29:35 · 66 阅读 · 0 评论