当前位置:网站首页>Single chain surface test questions
Single chain surface test questions
2022-07-29 06:24:00 【Tting_ twelve】
class HeroNode{
public int no;
public String name;
public String nickname;
public HeroNode next;
// Constructors
public HeroNode(int no, String name, Stirng nickname){
this.no = no;
this.name = name;
this.nickname = nickname;
}
}Sina interview questions --- Look up the last... In the single chain table k Nodes
Ideas :
1. Write a method , Accept head node , Receive one at the same time index
2.index Means the last index node
3. First, traverse the list from beginning to end , Get the number of nodes in the linked list
4. obtain size after , Start traversing from the first node of the linked list , Traverse size-index Nodes
//getLength() The method is to get the number of linked list nodes written by yourself
public static HeroNode findLastIndexNode(heroNOde head, int index){
if(head.next == null){
return null;
}
int size = getLength(head);
if(index <= 0 || index > size){
return null;
}
heroNode cur = head.next;
for(int i = 0; i < size - index; i++){
cur = cur.next;
}
return cur;
}Tencent interview questions --- Reverse the single chain table
Ideas
1. First define a node reverseHead = new HeroNode();
2. Go through the original list from beginning to end , Every time a node is traversed, it is taken out , And put it in the new list reverseHead The front end of
3. Of the original linked list head.next = reverseHead.next
public static void reversetList(HeroNode head){
// If the current linked list is empty or there is only one node , Return directly without inversion
if(head.next == null || head.next.next ==null){
return;
}
//
HeroNode cur = head.next;
HeroNode next = null; // The next node of the current node
HeroNode reversHead = new HeroNode(0,"","");
While(cur != null){
next = cur.next;
cur.next = reverseHead.next;
reverseHead.next = cur;
cur = next;
}
head.next = reverseHead.next;
}Baidu interview questions --- Print linked list from end to end
Ideas :
The above requirement is to print the linked list in reverse order
If you reverse first and then print, the original linked list will be destroyed. It is not recommended
We can use the data structure of stack , Push each node into the stack , Use the stack's first in, last out feature to achieve reverse printing
边栏推荐
- [beauty of software engineering - column notes] 13 | how to break the rhythm of writing code during daytime meetings and overtime?
- Eight sorts --------- quick sort
- Based on stc51: schematic diagram and source code of four axis flight control open source project (entry-level DIY)
- 网络安全学习篇
- leetcode---技巧
- synchronized八锁现象理解
- NOI Online 2022普及组 题解&个人领悟
- Leetcode 283. move zero
- 从头安装MYSQL(MYSQL安装文档-解压版)
- SQLyog 安装和配置教程
猜你喜欢

【Leetcode刷题】数组3——分治

官方教程 Redshift 06 Opt参数

传统模型预测控制轨迹跟踪——波浪形轨迹(功能包已经更新)

LeetCode #1.两数之和

Ml4 self study notes

Huawei cloud 14 day Hongmeng device development -day5 drive subsystem development

【软件工程之美 - 专栏笔记】29 | 自动化测试:如何把Bug杀死在摇篮里?

【软件工程之美 - 专栏笔记】28 | 软件工程师的核心竞争力是什么?(下)
![[beauty of software engineering - column notes] 19 | as a programmer, you should have product awareness](/img/32/180bfe5904366946fca0d987f4e8ad.png)
[beauty of software engineering - column notes] 19 | as a programmer, you should have product awareness

传统模型预测控制轨迹跟踪——圆形轨迹(功能包已经更新)
随机推荐
抽象类以及接口
FPGA based: multi-target motion detection (hand-in-hand teaching ①)
官方教程 Redshift 06 Opt参数
[beauty of software engineering - column notes] 17 | what is the need analysis? How to analyze?
简洁代码实现pdf转word文档
STM32 printf问题总结 semihosting microLIB理解
clickhouse 导入CSV失败 不报错但是无数据
Sqlyog installation and configuration tutorial
LeetCode #876.链表的中间结点
【软件工程之美 - 专栏笔记】22 | 如何为项目做好技术选型?
LeetCode #977.有序数组的平方
#6898 变幻的矩阵 题解
数论:px+py 不能表示的最大数为pq-p-q的证明
【软件工程之美 - 专栏笔记】28 | 软件工程师的核心竞争力是什么?(下)
【软件工程之美 - 专栏笔记】“一问一答”第3期 | 18个软件开发常见问题解决策略
Logistic regression - project practice - credit card detection task (Part 2)
太原市公交路线爬取
数学建模心得
链表--------------------尾插法
传统模型预测控制轨迹跟踪——圆形轨迹(功能包已经更新)