当前位置:网站首页>Understanding recursion
Understanding recursion
2022-06-12 13:34:00 【You stole my name】
The meaning of recursion
The Chinese understanding of recursion is transfer and regression , Passing means passing something between each level of recursion , Regression is to go back to the first recursion . Remember that a little recursive process is doing the same thing over and over again .
How to write recursion ?
A common template for recursion is :① The termination condition of recursion , That is, when the recursion ends ;② What this round of recursion needs to do , That is, the processing of data , Including the value returned by the next level of recursion and the current round of value processing ;③ This recursion needs to return the value of the upper recursion .
example
Try your best to explain the topic , The title is as follows :
Recursion is always processed up from the end of recursion . So its code is :/**
- Definition for singly-linked list.
- struct ListNode {
int val;ListNode *next;ListNode(int x) : val(x), next(NULL) {}- };
/
// recursive
class Solution {
public:
ListNode swapPairs(ListNode* head) {
// Recursive termination condition
if(headnullptr||head->nextnullptr)
return head;
// What this level recursion needs to do
ListNode *node=swapPairs(head->next->next);
ListNode *temp=head->next;
head->next=node;
temp->next=head;
// Return the value of upper level recursion
return temp;
}
};
边栏推荐
- 1005: estimation of the earth's population carrying capacity
- 创新实训(十)高级界面美化
- Possible solutions to problems after CodeBlocks installation
- xcode 调试openGLES
- Codeforces 1637 C. Andrew and stones - simple thinking
- Introduction to application design scheme of intelligent garbage can voice chip, wt588f02b-8s
- Codeforces 1629 A. download more RAM - simple greed
- Title: Yanghui triangle
- Getting started with NVIDIA Jetson nano Developer Kit
- C#DBHelper_FactoryDB_GetConn
猜你喜欢

How to balance multiple losses in deep learning?

Experience and learning path of introductory deep learning and machine learning

当字节跳动在美国输出中国式 996

事件的传递和响应以及使用实例

Automatic Generation of Visual-Textual Presentation Layout

Successfully rated Tencent t3-2, 10000 word parsing

leetcode 47. Permutations II full permutations II (medium)

The goods are full. You must take this knowledge

智能垃圾桶语音芯片应用设计方案介绍,WT588F02B-8S

Script引入CDN链接提示net::ERR_FILE_NOT_FOUND问题
随机推荐
Tinyxml Usage Summary
Pytorch framework
Computational hierarchy -- the problem of large numbers multiplying decimals
How to solve the problem of data table query error when SQLite writes the registration function?
Software construction 03 regular expression
创新实训(十一)开发过程中的一些bug汇总
达梦数据库DM8 windows环境安装
GPUImage链式纹理的简单实现
Seekg, tellg related file operations
[cloud native | kubernetes] learn more about ingress
[Title brushing] Super washing machine
A brief introduction to Verilog mode
字节序数据读写
Codeforces 1629 E. grid XOR - simple thinking
播放器屏幕方向方案
The problem of Joseph in Informatics
VGA display color bar and picture (FPGA)
FFmpeg 学习指南
Introduction to application design scheme of intelligent garbage can voice chip, wt588f02b-8s
torch_ geometric message passing network