# 剑指offer第四天

### 25.复杂链表的复制

/*
public class RandomListNode {
int label;
RandomListNode next = null;
RandomListNode random = null;

RandomListNode(int label) {
this.label = label;
}
}
*/
public class Solution {
{
//一定注意考虑输入为空链表的情况
//第一步：克隆每个结点的值和next，并且将新节点放置在对应旧结点之后
while(node != null){
RandomListNode cloneNode = new RandomListNode(node.label);
//cloneNode.label = node.label;
cloneNode.next = node.next;
node.next = cloneNode;
node = cloneNode.next;
}
//第二步：克隆每个随机指针
while(node != null){
RandomListNode cloneNode = node.next;
if(node.random != null)
cloneNode.random = node.random.next;
node = cloneNode.next;
}
//第三步：拆分拼接的链表
while(node != null){
RandomListNode cloneNode = node.next;
node.next = cloneNode.next;
node = node.next;
if(node != null)
cloneNode.next = node.next;
else
cloneNode.next = null;
}
}
}


### 26.二叉搜索树与双向链表

/**
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;

public TreeNode(int val) {
this.val = val;

}

}
*/
public class Solution {
public TreeNode Convert(TreeNode pRootOfTree) {
if(pRootOfTree == null) return null;
if(pRootOfTree.left == null && pRootOfTree.right == null) return pRootOfTree;
TreeNode left = Convert(pRootOfTree.left);
TreeNode node = left;

if(node == null)
pRootOfTree.left = null;
else{
while(node.right != null)
node = node.right;
pRootOfTree.left = node;
node.right = pRootOfTree;
}
TreeNode right = Convert(pRootOfTree.right);
pRootOfTree.right = right;
if(right != null)
right.left = pRootOfTree;
return left != null ? left : pRootOfTree;
}
}


### 27.字符串的排列

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Collections;
public class Solution {
ArrayList<String> result = new ArrayList<String>();
public ArrayList<String> Permutation(String str) {
if(str == null) return null;
char[] charArray = str.toCharArray();
permutation(charArray,0);
Collections.sort(result);
return result;
}
public void permutation(char[] charArray,int beginIdx){
if(beginIdx >= charArray.length) return;
if(beginIdx == charArray.length-1){
}
HashSet<Character> charSet = new HashSet<>();
for(int i = beginIdx;i<charArray.length;i++){
if(i == beginIdx){
permutation(charArray,beginIdx+1);
}else if(i != beginIdx && !charSet.contains(charArray[i])){
char temp = charArray[beginIdx];
charArray[beginIdx] = charArray[i];
charArray[i] = temp;
permutation(charArray,beginIdx+1);
temp = charArray[beginIdx];
charArray[beginIdx] = charArray[i];
charArray[i] = temp;
}
}
}
}


02-09 99

06-02 2019

08-05 1万+

08-27 1280

08-18 3332

08-29 1132

02-03 3万+

07-20 399

03-13 240

11-02 4万+

06-01 1216

08-09 4万+

04-06 2万+

09-02 557

03-19 501

01-13 132

06-04 47

02-02 3162

11-24 184

04-14 61万+

03-13 15万+

03-12 2556

02-28 1万+

03-01 14万+

03-08 1万+

03-08 8万+

03-10 13万+

03-10 19万+

#### MySQL数据库面试题（2020最新版）

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客