MCPcopy Create free account
hub / github.com/ROUTINE-STUDY/Algorithm / Ingyu

Class Ingyu

LeetCode/Greedy/1046. Last Stone Weight/Ingyu.java:3–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import java.util.Arrays;
2
3class Ingyu {
4 public int lastStoneWeight(int[] stones) {
5 //무게순으로 정렬.
6 Arrays.sort(stones);
7 //스톤이 1개밖에 없으면 바로 첫번째 돌 리턴.
8 if (stones.length <= 1) {
9 return stones[0];
10 }
11
12 int index = stones.length - 1; //맨끝에 최대값을 가르키게 함.
13 while (stones[1] != 1001) {
14 int temp = stones[index];
15 stones[index] = 1001;
16 stones[index - 1] = temp - stones[index - 1];
17 index--;
18 Arrays.sort(stones);
19 }
20
21 return stones[0];
22 }
23}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected