当前位置:网站首页>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
边栏推荐
猜你喜欢
Maya ACES工作流程配置(Arnold 及 RedShift 贴图配置规范-还原出SP-Aces流程下贴图正确的效果) PS还原Aces流程下渲染的图
官方教程 Redshift 06 Opt参数
Ml8 self study notes
Simple code to realize PDF to word document
Leetcode 1. sum of two numbers
Traditional model predictive control trajectory tracking - circular trajectory (function package has been updated)
Traditional model predictive control trajectory tracking - wavy trajectory (function package has been updated)
Dynamic planning summary
传统模型预测控制轨迹跟踪——圆形轨迹(功能包已经更新)
【软件工程之美 - 专栏笔记】26 | 持续交付:如何做到随时发布新版本到生产环境?
随机推荐
【软件工程之美 - 专栏笔记】20 | 如何应对让人头疼的需求变更问题?
NOI Online 2022普及组 题解&个人领悟
LeetCode #1.两数之和
计算机大厂面试题
网络爬虫
LeetCode #7.整数反转
Eight sorts ------------- heap sort
UE5 landscape 换算 Nanite 转换方式及不支持 配合 Lumen及Lumen开启 Dynamic Mesh 使用方法
[beauty of software engineering - column notes] 14 | project management tools: all management problems should be considered whether they can be solved by tools
FPGA based: multi-target motion detection (hand-in-hand teaching ①)
IDEA 实用快捷键 新手必看
LeetCode #344.反转字符串
Operating system interview questions
Computer factory interview questions
[beauty of software engineering - column notes] 13 | how to break the rhythm of writing code during daytime meetings and overtime?
唯美girls
【软件工程之美 - 专栏笔记】21 | 架构设计:普通程序员也能实现复杂系统?
Leetcode 167. sum of two numbers II - input ordered array
传统模型预测控制轨迹跟踪——波浪形轨迹(功能包已经更新)
Eight sorts ----------- bubble sort