2019-04-23  251 views 评论

# [leetcode]题目解析（190423）

标签：

## Remove duplicates from sorted list

### 题目描述

Given a sorted linked list, delete all duplicates such that each element appear only once.For example,
Given1->1->2, return1->2.
Given1->1->2->3->3, return1->2->3.（保留1个）

### 题目解析

• 不断判断下面有几个点和当前点相等，代码如下：

• 找到最后一个点和当前点相等的时候，直接把那个点的next赋值给当前点的next，然后那些点。即：

## Jump Game

### 题目说明

Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are able to reach the last index.For example:
A =[2,3,1,1,4], returntrue.A =[3,2,1,0,4], returnfalse.

### 题目解析

• 当前是第i个元素，但是i已经大于n-1了（下标从0开始，所以第n个数是第n-1）。
• A[i]为0：这里面又分两种情况，一种是如题目所给的第2种情况，在中间为0的这个位置不走了，还有一种情况是我这个数组一共1个元素，就是0。那么跳出。

## rotate image

### 题目描述

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:
Could you do this in-place?

## Trapping Rain Water

### 题目描述

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example,
Given[0,1,0,2,1,0,1,3,2,1,2,1], return6.

The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcosfor contributing this image!