
数据结构与算法
算法刷题期间所遇到的一些问题
好吃还得是柚子
首先,少年,答应了别人的事就一定要做到
展开
-
2021-08-31
构造链表的结构体(数据、指针)struct node{ int data; // 数据 node* next; // 指针};使用new运算符为节点分配内存node* p = new node;编写创建列表函数,参数为链表的长度(从用户cin输入读入),返回值为创建的列表的头指针node* create(int len){ node *p, *pre, *head; // 临时指针,指向前驱节点,头指针 head = new node; // 为头指针分配内存原创 2021-08-31 23:17:23 · 245 阅读 · 0 评论 -
算法刷题时使用if else if与连续if if语句的区别
使用if else输出结果为1#include <iostream>using namespace std;int main () { int a1=1, a2=2, a3=3, a4=4; if (a1 == 1) cout << a1; else if (a2 == 2) cout << a2; else if (a3 == 3) cout << a3; else if (a4 == 4) cout <<原创 2021-02-14 11:31:58 · 1118 阅读 · 2 评论 -
数组中未出现的最小正整数
问题描述:给你一个未排序的整数数组 nums ,请你找出其中没有出现的最小的正整数。要求 :解决方案实现时间复杂度为 O(n) 并且只使用常数级别额外空间。本地编译器运行代码如下:#include<iostream>using namespace std;void swap(int* arr, int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp;}int main() { int a.原创 2021-02-05 08:35:01 · 804 阅读 · 0 评论 -
如何在本地编译器上调试leetcode的代码
题目描述题目链接:https://leetcode-cn.com/problems/two-sum在leetcode上的解题代码class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { map<int,int> tmp; // 建立hash表存放数组元素 vector<int> res(2,-1)原创 2021-02-01 11:57:01 · 4442 阅读 · 2 评论