topic
Specific topics do not remember clearly is
substantially:
1. When the AAA occurs, it is converted to AA output
when 2.AABB, converted to an output AAB
Thinking
// define the speed of the pointer
// slow, fast, hands-defined test the Test
// before the FAST slow one, if the index [fast] = index [slow ]. test == fast + 1 to see if the next fast same
// If the same, the position of the empty set, slow and fast are slow moving backwards
// test and fast is not the same, then both slow and fast forward If the value of fast moving two instructions is equal to slow AABB, then slow empty set
// or set 9999;
Code
/**
*
*/
/***
* @author 18071
* @Date 2019年3月18日
* 功能:
***/
public class test2 {
public static void main(String args[]) {
solution1 s =new solution1 ();
int [] x = {1,1,1,2,2,3,3};
s.so(x);
for(int i=0;i<x.length;i++) {
if(x[i]<9999) {
System.out.println(x[i]);
}
}
}
}
class solution1 {
public void so (int [] index) {
//定义快慢指针
// slow,fast,定义测试指针 test
//fast 在slow之前一位,如果index[fast]==index[slow] 则fast向后以,test==fast+1 查看下一位是否与fast相同
//如果相同,将slow的位置置位空,slow与fast都向后移动
//test与fast不相同 ,则将 slow与fast都向前移动2位如果fast的值等于slow 说明是AABB ,则将slow置位空
//或者置位 9999;
int fast=1;
int slow =0;
while(fast<index.length-1) {
if(index[fast]==index[slow]) {
int text = fast+1;
if(text < index.length) {//没有到达末尾
if(index[text]==index[fast]) {
//情况1: 三个连着的相等
index[slow]=9999;
// slow++;
// fast++;
//break;
}
if(index[text]!=index[fast]) {
//判断AABB
if(fast+2<index.length) {
fast=fast+2;
slow=slow+2;
if(index[slow]==index[fast]) {
index[slow]=9999;
}
}
}
}
}
slow++;
fast++;
}
}
}
result
And expect the same results, but does not guarantee that all cases by