613. Shortest Distance in a Line--ABS() and MIN()
来源:互联网 发布:linux 关闭系统 编辑:程序博客网 时间:2024/05/17 07:29
Question
Table point
holds the x coordinate of some points on x-axis in a plane, which are all integers.Write a query to find the shortest distance between two points in these points.| x ||-----|| -1 || 0 || 2 |
The shortest distance is '1' obviously, which is from point '-1' to '0'. So the output is as below:| shortest||---------|| 1 |
Note: Every point is unique, which means there is no duplicates in table point
.Follow-up: What if all these points have an id and are arranged from the left most to the right most of x axis?
SELECT MIN(ABS(p1.x - p2.x)) AS shortestFROM point p1 JOIN point p2 ON p1.x != p2.x;
Question
Tablepoint
holds the x coordinate of some points on x-axis in a plane, which are all integers.Write a query to find the shortest distance between two points in these points.| x ||-----|| -1 || 0 || 2 |The shortest distance is '1' obviously, which is from point '-1' to '0'. So the output is as below:| shortest||---------|| 1 |Note: Every point is unique, which means there is no duplicates in tablepoint
.Follow-up: What if all these points have an id and are arranged from the left most to the right most of x axis?
阅读全文
0 0
- 613. Shortest Distance in a Line--ABS() and MIN()
- math.min() and math.abs()
- PAT A Shortest Distance (20)
- 【DP】 Shortest Edit Distance in C
- Proxies for Shortest Path and Distance Queries
- PAT-A 1046. Shortest Distance (20)
- C++ Find Min and Max element in a BST
- In a Line
- In a Line
- Coins in a Line
- Boxes in a Line
- coins in a line
- Coins in a Line
- Is there any way to define a min and max value for edittext in android?
- Shortest path in a Maze | Lee algorithm
- 1046. Shortest Distance
- pat 1046 Shortest Distance
- 1046. Shortest Distance (20)
- leetcode10
- 超绚丽的HTML5地图分布动画
- 一个简易的“返回顶部”页面效果
- linux top命令参数详细介绍
- 网络基础知识(一)半双工与全双工
- 613. Shortest Distance in a Line--ABS() and MIN()
- Linux网络编程--sendfile零拷贝高效率发送文件
- Hat’s Words
- 文件在本地服务器不留痕迹的下载
- e-Coins POJ
- Nginx SSI 设置
- LeetCode---2.Two Sum
- HDU-4238-You Are the One (区间DP)
- Numpy 花式索引