mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-29 15:13:44 +00:00
Update 代码可读性.md
更新示例代码,使其可以编译运行。
This commit is contained in:
+7
-7
@@ -272,17 +272,17 @@ var setFirstEmptyInput = function(new_value) {
|
||||
|
||||
```java
|
||||
int findClostElement(int[] arr) {
|
||||
int clostIdx;
|
||||
int clostDist = Interger.MAX_VALUE;
|
||||
int clostIdx = -1;
|
||||
int clostDist = Integer.MAX_VALUE;
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
int x = ...;
|
||||
int y = ...;
|
||||
int z = ...;
|
||||
int value = x * y * z;
|
||||
int dist = Math.sqrt(Math.pow(value, 2), Math.pow(arr[i], 2));
|
||||
int dist = (int) Math.sqrt(Math.pow(value, 2) + Math.pow(arr[i], 2));
|
||||
if (dist < clostDist) {
|
||||
clostIdx = i;
|
||||
clostDist = value;
|
||||
clostDist = dist;
|
||||
}
|
||||
}
|
||||
return clostIdx;
|
||||
@@ -293,13 +293,13 @@ int findClostElement(int[] arr) {
|
||||
|
||||
```java
|
||||
public int findClostElement(int[] arr) {
|
||||
int clostIdx;
|
||||
int clostDist = Interger.MAX_VALUE;
|
||||
int clostIdx = -1;
|
||||
int clostDist = Integer.MAX_VALUE;
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
int dist = computDist(arr, i);
|
||||
if (dist < clostDist) {
|
||||
clostIdx = i;
|
||||
clostDist = value;
|
||||
clostDist = dist;
|
||||
}
|
||||
}
|
||||
return clostIdx;
|
||||
|
||||
Reference in New Issue
Block a user