当前位置:网站首页>Sword finger offer 06 Print linked list from end to end
Sword finger offer 06 Print linked list from end to end
2022-07-05 08:21:00 【Programmer Xiao Li】
subject :
Enter the head node of a linked list , Return the value of each node from the end to the end ( Return with array ).
Example 1:
Input :head = [1,3,2]
Output :[2,3,1]
Limit :
0 <= Chain length <= 10000
Ideas :
Use the stack to complete the traversal of the linked list , Finally, play the stack in turn to get the results .
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public int[] reversePrint(ListNode head) {
Stack<ListNode> stack = new Stack<>();
int counter = 0;
while(head != null){
counter++;
stack.push(head);
head = head.next;
}
int[] array = new int[counter];
for (int i = 0; i < counter; i++){
array[i] = stack.pop().val;
}
return array;
}
}
边栏推荐
- Measurement fitting based on Halcon learning [i] fuse Hdev routine
- 关于线性稳压器的五个设计细节
- C WinForm [view status bar -- statusstrip] - Practice 2
- DCDC circuit - function of bootstrap capacitor
- VESC Benjamin test motor parameters
- 实例009:暂停一秒输出
- Charge pump boost principle - this article will give you a simple understanding
- Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
- H264 (I) i/p/b frame gop/idr/ and other parameters
- QEMU STM32 vscode debugging environment configuration
猜你喜欢

Count the number of inputs (C language)

Brief discussion on Buck buck circuit

STM32---IIC

STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
![[tutorial 19 of trio basic from introduction to proficiency] detailed introduction of trio as a slave station connecting to the third-party bus (anybus PROFIBUS DP...)](/img/54/2fe86f54af01f10de93818103f2154.jpg)
[tutorial 19 of trio basic from introduction to proficiency] detailed introduction of trio as a slave station connecting to the third-party bus (anybus PROFIBUS DP...)

FIO测试硬盘性能参数和实例详细总结(附源码)
![[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication](/img/08/7f28008a4aa999650998ba8dee5d8e.jpg)
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication

Connection mode - bridge and net

PMSM dead time compensation
![C WinForm [help interface - send email] - practice five](/img/2a/c4e7abe054e6fdd45acc7d297a033d.jpg)
C WinForm [help interface - send email] - practice five
随机推荐
DokuWiki deployment notes
STM32 tutorial triple ADC interleaved sampling
Shell script
Adaptive filter
Several important parameters of LDO circuit design and type selection
【论文阅读】2022年最新迁移学习综述笔注(Transferability in Deep Learning: A Survey)
STM32 --- configuration of external interrupt
Sizeof (function name) =?
What are the test items of power battery ul2580
go依赖注入--google开源库wire
C WinForm [get file path -- traverse folder pictures] - practical exercise 6
实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
Live555 push RTSP audio and video stream summary (III) flower screen problem caused by pushing H264 real-time stream
Buildroot system for making raspberry pie cm3
Matlab2018b problem solving when installing embedded coder support package for stmicroelectronic
Management and use of DokuWiki
Synchronization of QT multithreading
STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
Soem EtherCAT source code analysis I (data type definition)
STM32 --- NVIC interrupt