# Define an array to be a railroad-tie array if the following three conditions hold

3. Define an array to be a railroad-tie array if the following three conditions hold a. The array contains at least one non-zero element
b. Every non-zero element has exactly one non-zero neighbor
c. Every zero element has two non-zero neighbors.
For example, {1, 2, 0, 3, -18, 0, 2, 2} is a railroad-tie array because a = 1 has exactly one non-zero neighbor (a)
a = 2 has exactly one non-zero neighbor (a) a = 0 has two non-zero neighbors (a and a) a = 3 has exactly one non-zero neighbor (a) a = -18 has exactly one non-zero neighbor (a) a = 0 has two non-zero neighbors (a and a) a = 2 has exactly one non-zero neighbor (a) a = 2 has exactly one non-zero neighbor (a) The following are not railroad-tie arrays
{1, 2, 3, 0, 2, 2}, because a=2 has two non-zero neighbors.
{0, 1, 2, 0, 3, 4}, because a=0 has only one non-zero neighbor (it has no left neighbor)
{1, 2, 0, 0, 3, 4}, because a=0 has only one non-zero neighbor (a)
{1}, because a=1 does not have any non-zero neighbors.
{}, because the array must have at least one non-zero element
{0}, because the array must have at lease one non-zero element.
Write a function named isRailroadTie which returns 1 if its array argument is a railroad-tie array; otherwise it returns 0.
If you are writing in Java or C#, the function signature is
If you are writing in C or C++, the function signature is
int isRailroadTie(int a[ ], int len) where len is the number of elements in the array a

java代码实现：

```public class RailroadTie {
public static void main(String[] args) {

//        int [] a={1, 2, 0, 3, -18, 0, 2, 2};
//        int [] a={1, 2, 3, 0, 2, 2};
//        int [] a={0, 1, 2, 0, 3, 4};
//        int [] a={1, 2, 0, 0, 3, 4};
//        int [] a={1};
//        int [] a={};
//        int [] a={0};
//        int [] a={1, 2};
//        int [] a={1, 2, 0, 1, 2, 0, 1, 2};
//        int [] a={3, 3, 0, 3, 3, 0, 3, 3, 0, 3, 3};
//        int [] a={0, 0, 0, 0};
//        int [] a={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int [] a={1, 3, 0, 3, 5, 0};

}

/**
* 1.至少有一个非零数
* 2.每个非0元素相邻有一个非零
* 3.每个0元素有2个非零相邻
* @param a
* @return
*/
public static int isRailroadTie (int [] a) {

if(a.length <=1){
return 0;// 至少有个元素
}

if(a==0||a[a.length-1]==0){
return 0;
}

for (int i = 1; i < a.length-1; i++) {

if(a[i]==0){
if(a[i-1]==0||a[i+1]==0){
return 0;
}
}else {
if( !(a[i-1]==0 || a[i+1]==0)){
return 0;
}
}

}

return 1;

}
}```

## 淘宝卖什么虚拟产品赚钱(月入2万+) 