---
title: "多益笔试题链表是否有环"
author: "chentingk"
date: "2015-03-21T13:24:42Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2015-03-21T13:24:42Z"
id: 2194447
url: "https://chentingk.iteye.com/blog/2194447"
---

数据结构做得少，被坑得外焦里嫩~

是否有环，代码量如此低……

```
bool IfCircle(LinkList *root)
{
	/*
		追赶式验证是否存在环
	*/
	LinkList *fast=root;
	LinkList *slow=root;
	while(fast && slow)
	{
		fast=fast->p_next;
		fast=fast->p_next;
		if(fast==slow)
			return true;
		slow=slow->p_next;
	
	}
	return false;



}
```

 

附加一道数学题吧

```
int test3(int x)
{
	int count=0;
	while(x)
	{
		x=x&(x-1);
		count++;
	}
	return count;

}
```

 

转成二进制有多少个1count就有多少