Notice
Recent Posts
Recent Comments
Link
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 프로그래머스 소수
- 리눅스 777
- Web Service Architecture
- 프로그래머스
- beautifulsoup
- 와스 웹서버의 차이
- 리눅스 rwx
- 단순 반복 자동화
- 파이썬 가상환경
- 프로그래머스 SQL
- 파이썬 주식
- WAS WebServer 차이
- 파이썬
- string format
- 트레이딩 봇 만들기
- java
- BigDecimal
- spring
- 즐겨찾기가 가장 많은 식당 정보 출력하기
- JavaScript Obejct Notation
- pybithumb
- 변동성 돌파전략
- 리눅스
- 오라클
- JSON특징
- Web Server란
- 빗썸 API 사용
- JSON 형식
- Python
- WAS란
Archives
- Today
- Total
IT 개발자_S
[코딜리티] TapeEquilibrium 본문
반응형
1. 배열 값이 주어지고
2. p 값에 따라 0~ p 까지 p +1 ~n 까지의 합을 구한후 서로 빼줌
3. 이중 for문을 걸지 않게 유의
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int [] prefix_sum = new int[A.length];
int sum = 0;
int min = Integer.MAX_VALUE;
// long totSum = Arrays.stream(A).sum();
long totSum =0;
for(int i : A) totSum += i;
int sumArray =(int)totSum;
for (int i=0; i < A.length -1; i++){
sum += A[i];
sumArray -=A[i];
if(min > Math.abs ((sumArray -sum))){
min = Math.abs (sumArray -sum);
}
// System.out.println(i +" @ " + sumArray + " !" + sum) ;
}
/*
p=1 a[0] - a[1] ~ a[n-1]
p2 a[0]+ a[1 ] - a[2] ~ a[n-2]
*/
return min;
}
}
반응형
'IT > 알고리즘_JAVA' 카테고리의 다른 글
[프로그래머스] 완주하지 못한 선수 (0) | 2020.05.27 |
---|---|
[코딜리티]FrogRiverOne (0) | 2020.05.11 |
[코딜리티]PermMissingElem (0) | 2020.05.10 |
[코딜리티]Frog_jump (0) | 2020.05.10 |
[코딜리티]OddOccurrencesInArray (0) | 2020.05.09 |
Comments