> For the complete documentation index, see [llms.txt](https://aaronice.gitbook.io/lintcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aaronice.gitbook.io/lintcode/problem-solving-summary/tips-for-avoiding-bugs.md).

# Tips for Avoiding Bugs

## 边界条件

循环时的起始和终止，比如数组、矩阵、链表中，注意何时开始循环，又是何时终止循环。

Tips: 用实际例子，模拟过程，确定边界处理的方式，再通过特殊的输入条件验证这种处理方式是否通行。

## 特殊输入

一些算法在特殊输入情况下会出问题。

比如null，length = 0，invalid输入，重复元素。

## 贪心算法的普适性

贪心算法往往得到的是局部最优local optimal，如何扩展到全局最优，很多时候需要更严谨的证明。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://aaronice.gitbook.io/lintcode/problem-solving-summary/tips-for-avoiding-bugs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
