From 269598b5b19692a23e3312c2dcccb865df794ae8 Mon Sep 17 00:00:00 2001 From: SSOOYA Date: Mon, 16 Oct 2023 14:17:15 +0900 Subject: [PATCH] =?UTF-8?q?solve/#168:=20=ED=94=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EB=9E=98=EB=A8=B8=EC=8A=A4=20=EC=97=B0=EC=86=8D=20=ED=8E=84?= =?UTF-8?q?=EC=8A=A4=20=EB=B6=80=EB=B6=84=20=EC=88=98=EC=97=B4=EC=9D=98=20?= =?UTF-8?q?=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AlgorithmReview.xcodeproj/project.pbxproj | 4 +++ ...54\227\264\354\235\230 \355\225\251.swift" | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 "AlgorithmReview/Programmers/Lv3/\354\227\260\354\206\215 \355\216\204\354\212\244 \353\266\200\353\266\204 \354\210\230\354\227\264\354\235\230 \355\225\251.swift" diff --git a/AlgorithmReview.xcodeproj/project.pbxproj b/AlgorithmReview.xcodeproj/project.pbxproj index 5492081..5bed6c9 100644 --- a/AlgorithmReview.xcodeproj/project.pbxproj +++ b/AlgorithmReview.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ EEBC48342AD9343C000BBAF1 /* 셔틀버스.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEBC48332AD9343C000BBAF1 /* 셔틀버스.swift */; }; EEC10A8A2A9EE99900882987 /* 입국 심사.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEC10A892A9EE99900882987 /* 입국 심사.swift */; }; EEC5CAF129B0677900FF4C26 /* 로또의 최고 순위와 최저 순위.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEC5CAF029B0677900FF4C26 /* 로또의 최고 순위와 최저 순위.swift */; }; + EECBCFEE2ADCFEB90056BC96 /* 연속 펄스 부분 수열의 합.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECBCFED2ADCFEB90056BC96 /* 연속 펄스 부분 수열의 합.swift */; }; EED6FC712A020BE5006F6D72 /* 2493.swift in Sources */ = {isa = PBXBuildFile; fileRef = EED6FC702A020BE5006F6D72 /* 2493.swift */; }; EED6FC772A036698006F6D72 /* 2800.swift in Sources */ = {isa = PBXBuildFile; fileRef = EED6FC762A036698006F6D72 /* 2800.swift */; }; EEEA901A2A89DC6F00EBE008 /* 수식 최대화.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEEA90192A89DC6F00EBE008 /* 수식 최대화.swift */; }; @@ -167,6 +168,7 @@ EEC10A892A9EE99900882987 /* 입국 심사.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "입국 심사.swift"; sourceTree = ""; }; EEC5CAF029B0677900FF4C26 /* 로또의 최고 순위와 최저 순위.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "로또의 최고 순위와 최저 순위.swift"; sourceTree = ""; }; EEC5E3632A6A2CB8007929D6 /* 숫자 카드 나누기.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "숫자 카드 나누기.swift"; sourceTree = ""; }; + EECBCFED2ADCFEB90056BC96 /* 연속 펄스 부분 수열의 합.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "연속 펄스 부분 수열의 합.swift"; sourceTree = ""; }; EECCE33829B9A12E00838047 /* 키패드 누르기.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "키패드 누르기.swift"; sourceTree = ""; }; EECCE33F29BADE8500838047 /* 크레인 인형뽑기 게임.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "크레인 인형뽑기 게임.swift"; sourceTree = ""; }; EECEB2632A6F8BC300FBD5D8 /* 테이블 해시 함수.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "테이블 해시 함수.swift"; sourceTree = ""; }; @@ -449,6 +451,7 @@ EE31346F2AD51D670092C902 /* 징검다리 건너기.swift */, EE8F05042AD6695900B70351 /* 경주로 건설.swift */, EEBC48332AD9343C000BBAF1 /* 셔틀버스.swift */, + EECBCFED2ADCFEB90056BC96 /* 연속 펄스 부분 수열의 합.swift */, ); path = Lv3; sourceTree = ""; @@ -548,6 +551,7 @@ EEAEC89F298CACDD001B1D62 /* main.swift in Sources */, EE5CEEC62A39A6BB00E1907E /* 가장 큰 정사각형 찾기.swift in Sources */, EE2738C429C193A3006077A3 /* 대충 만든 자판.swift in Sources */, + EECBCFEE2ADCFEB90056BC96 /* 연속 펄스 부분 수열의 합.swift in Sources */, EE2E5E6C29B5884D00545253 /* 체육복.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git "a/AlgorithmReview/Programmers/Lv3/\354\227\260\354\206\215 \355\216\204\354\212\244 \353\266\200\353\266\204 \354\210\230\354\227\264\354\235\230 \355\225\251.swift" "b/AlgorithmReview/Programmers/Lv3/\354\227\260\354\206\215 \355\216\204\354\212\244 \353\266\200\353\266\204 \354\210\230\354\227\264\354\235\230 \355\225\251.swift" new file mode 100644 index 0000000..f0e18e4 --- /dev/null +++ "b/AlgorithmReview/Programmers/Lv3/\354\227\260\354\206\215 \355\216\204\354\212\244 \353\266\200\353\266\204 \354\210\230\354\227\264\354\235\230 \355\225\251.swift" @@ -0,0 +1,31 @@ +// +// 연속 펄스 부분 수열의 합.swift +// AlgorithmReview +// +// Created by 박소윤 on 2023/10/16. +// + +import Foundation + +func solution(_ sequence:[Int]) -> Int { + + let first = sequence.first! + var ans = max(first, -first) + + func check(_ remain: Int) { + + var dp = [Int](repeating: 0, count: sequence.count) + dp[0] = 0 == remain ? -sequence[0] : sequence[0] + + for idx in (1..