自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(13)
  • 收藏
  • 关注

原创 股票问题

121. 买卖股票的最佳时机给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。如果你最多只允许完成一笔交易(即买入和卖出一支股票一次),设计一个算法来计算你所能获取的最大利润。注意:你不能在买入股票前卖出股票。示例 1:输入: [7,1,5,3,6,4]输出: 5解释: 在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格;同时,你不能在买入前卖出股

2020-12-02 23:44:09 105

原创 AVL

#include<stdio.h>#include<stdlib.h>typedef struct treenode{ int data; struct treenode*Lchild, *Rchild; int bf;}tree,*bstree;void LeftBalance(bstree *T);void RightBalance(bstree *T);void RR(bstree *T)//右旋:对以*T为根的树做右旋,(*T往右下压下去){ t

2020-11-10 23:03:35 78

原创 学生系统文件C++

二进制文件读写,链表操作student.h#pragma once#include <iostream>#include<cstring>using namespace std;class person{protected: char name[20]; int age;public: person(); person(char *pname, int page); char *get_name() { return name;} int get_a

2020-11-06 23:24:20 122

原创 学生文件

typedef struct student{ int num; char name[20]; int score; struct student *next;}stu;stu *cre(){ stu*head = (stu*)malloc(sizeof(stu)); head->next = NULL; return head;}stu* m = cre();//全局链表stu *sort(stu*head){ //冒泡排序 stu*p = head;

2020-10-11 16:17:00 160

原创 有序链表转换为二叉搜索树

#include<stdio.h>#include<stdlib.h> struct ListNode { int val; struct ListNode *next; }; struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; };struct ListNode*createList(struct ListNode*p)//建

2020-08-18 16:19:23 111

原创 堆排序

基本思想将待排序序列构造成一个大顶堆,此时,整个序列的最大值就是堆顶的根节点。将其与末尾元素进行交换,此时末尾就为最大值。然后将剩余n-1个元素重新构造成一个堆,这样会得到n个元素的次小值。如此反复执行,便能得到一个有序序列了。void heapify_D(int tree[], int n, int i){//最大值 if (i >= n) {return;} //n是节点总数 int lchild = 2 * i + 1;//i是当前节点 int rchild = 2 * i +

2020-08-12 12:53:35 73

原创 希尔排序

希尔排序(Shell’s Sort)是插入排序的一种又称“缩小增量排序”(Diminishing Increment Sort),是直接插入排序算法的一种更高效的改进版本。希尔排序是非稳定排序算法。希尔排序是把记录按下标的一定增量分组,对每组使用直接插入排序算法排序;随着增量逐渐减少,每组包含的关键词越来越多,当增量减至1时,整个文件恰被分成一组,算法便终止。void print(int p[], int lengh){ for (int i = 0; i < lengh; i++) {

2020-07-22 22:33:27 57

原创 快速排序

快排将一个序列的第一个值设为基准,设置low和high,每次排序将其划分为两部分,“中间值”的左边都小于它,“中间值”的右边都大于它。递归调用,得出最终结果。#include "stdafx.h"#include "stdio.h"void print(int a[]){ for (int i = 0; i < 7; i++) { printf("%d ", a[i]); } printf("\n");}int sort(int a[], int low, int high

2020-07-22 16:06:31 70

原创 1033移动石子

两边一次移动到与b挨着则最短移动距离,每次移动一个位置则为最长移动距离。int* numMovesStones(int a, int b, int c, int* returnSize){ //int answer[2]={0}; int *answer = (int *)malloc(sizeof(int) * 2); int minimum_moves=0, maximum_moves = 0; int aa = a, bb = b, cc = c; if (a == b || a == c

2020-07-09 10:54:04 97

原创 滑动窗口的最大值

#include "stdafx.h"#include "stdio.h"#include "malloc.h"int max(int *num, int left, int right)//求出一个窗口的最大值{ int maxnum = num[left]; for (int i = left; i <= right; i++) { if (num[i]>maxnum)maxnum = num[i]; } return maxnum;}int* maxSliding

2020-07-09 10:42:10 248

原创 力扣合并K个链表

/*struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* mergetwolist(struct ListNode *alist,struct ListNode *blist){ if (alist==NULL) { return blist; } if (blist==NULL) { return

2020-06-06 11:32:25 108

原创 LeetCode1290

1290二进制链表转整数 一个单链表引用节点head中,每个节点的值都是1或者0, 返回它所表示的十进制数。我新手想的笨办法,先求得总的节点个数,结果用pow函数累加出来。完整代码int getDecimalValue(struct ListNode* head){ int n=1; int num=0; if(head==NULL) ...

2020-02-20 13:04:07 170

原创 leetcode21

合并两个有序链表 我的做法是将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。先将两个有序链表连接起来struct ListNode*p=l1; struct ListNode*q=l2; while(p->next!=NULL) p=p->next; p->next...

2020-02-20 12:40:47 86

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除