반응형

시간 복잡도: O(N) --> 100%의 정답률

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A):
    # write your code in Python 3.6
    
    right_map = {}
    left_map = {}
    
    for i in A:
        try:
            right_map[i] += 1
        except:
            right_map[i] = 1
    
    count = 0
    left_leader = 0
    left_length = 0
    right_length = len(A)
    left_leader_count = 0
   
    for i in range(len(A)):
        right_map[A[i]] -= 1
        right_length -= 1
        
        try:
            left_map[A[i]] += 1
        except:
            left_map[A[i]] = 1
            
        left_length += 1
        
        # get left leader
        if left_map[A[i]] > left_leader_count:
            left_leader = A[i]
            left_leader_count = left_map[A[i]]
        
        # get equi leader
        if right_map[left_leader] > right_length//2 and left_leader_count > left_length//2: 
            count += 1
        
    
    return count
        
    
    pass
반응형

'Codility' 카테고리의 다른 글

Codility - MaxProfit 문제풀이  (0) 2020.05.19
Codility - MaxDoubleSliceSum 문제풀이  (0) 2020.05.19
Codility - StoneWall  (0) 2020.05.09
Codility - Nesting 문제풀이  (1) 2020.04.28
Codility - Fish  (0) 2020.04.27
반응형

터미널 창에 들어가서 kill 명령어 실행한다.

kill $(pgrep -f flask)
반응형
반응형

어느정도 수월하게 풀었다..!

 

휴~~ 앞으로도 성실하게 계속 전진해야게따

 

시간 복잡도: O(N*log(N)) or O(N) --> 100%의 정답률

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A):
    # write your code in Python 3.6
    
    half_num_of_arr = int(len(A)/2)
    
    dominator_arr = {}
    
    
    for i in range(len(A)):
        if A[i] in dominator_arr:
            dominator_arr[A[i]].append(i)
        else:
            dominator_arr[A[i]] = [i]
            
    arr = sorted(dominator_arr.items(), key=lambda x: len(x[1]), reverse = True)
    
    try:
        if len(arr[0][1]) > half_num_of_arr:
            return arr[0][1][0]
        else:
            return -1
    except:
        return -1
    
    
    pass

 

henry야 화이팅~~~!!

반응형
반응형

 

 

시간 복잡도: O(N) --> 100%의 정답률

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(H):
    # write your code in Python 3.6
    
    block_cnt = 0
    stack_arr = []
    
    for i in range(len(H)):
        while len(stack_arr) > 0 and stack_arr[-1] > H[i]:
            stack_arr.pop()
        
        if len(stack_arr) == 0 or stack_arr[-1] < H[i]:
            block_cnt += 1
            stack_arr.append(H[i])
            
    return block_cnt
            
    pass

 

내가 풀고 싶었는데, 너무 안풀려서 구글링을 통해 정답 보고

접근 방법에 대해서 알 수 있었다.ㅜㅜ

 

이렇게 실력이 느는거겠지 뭐..!!

 

화이팅 Henry야~~

 

 

 

 

 

뒤늦게 다시 한번 풀어봤다!!

 

그랬더니 이전 풀이가 어느정도 익숙해져서인지

100 점 나왔다! 오예~~~커퓌~~

 

 

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(H):
    # write your code in Python 3.6
    
    if len(H) == 1:
        return 1
    
    block_cnt = 1
    
    stack_arr = []
    stack_arr.append(H[0])
    
    for i in range(1, len(H)):
        if stack_arr[-1] < H[i]:
            stack_arr.append(H[i])
            block_cnt += 1
            
        elif stack_arr[-1] == H[i]:
            continue
        
        else:
            while True:
                stack_arr.pop()
                if len(stack_arr) == 0:
                    stack_arr.append(H[i])
                    block_cnt += 1
                    break
            
                if stack_arr[-1] < H[i]:
                    stack_arr.append(H[i])
                    block_cnt += 1
                    break
                    
                elif stack_arr[-1] > H[i]:
                    continue
                else:
                    break
    
    return block_cnt     
    pass

 

관련 유튜브 강의도 있습니다~~ㅎㅎ

https://www.youtube.com/watch?v=0rRakwhbgqU

 

저의 강의입니다~~ㅋㅋㅋ

반응형

'Codility' 카테고리의 다른 글

Codility - MaxDoubleSliceSum 문제풀이  (0) 2020.05.19
Codility - EquiLeader 문제풀이  (0) 2020.05.18
Codility - Nesting 문제풀이  (1) 2020.04.28
Codility - Fish  (0) 2020.04.27
Codility - Brackets  (0) 2020.04.27
반응형
def solution(lines):
    answer = 0
    
    arr = []
    
    for i in lines:
        tmp = i.split(" ")
        print(tmp)
        T_sec = float(tmp[2][:-1])
        end_time = int(tmp[1][:2])*3600000 + int(tmp[1][3:5])*60000 + int(tmp[1][6:8])*1000 + int(tmp[1][-3:])
        start_time = end_time - T_sec*1000 + 1
        print("S :" , start_time)
        print("T_sec : ", T_sec*1000)
        print("E :" , end_time)
        
        arr.append((end_time,-1))
        arr.append((start_time,1))
    
    arr = sorted(arr)
    print(arr)
    
    count = 0
    
    for i in range(len(arr)):
        
        
        # 연다
        if i[1] == 1:
            count += 1
        else:
            
        
        
        
        
        
        
    
    
    
    
    return answer

59%의 정확도

def solution(lines):
    answer = 0
    
    if len(lines) == 1:
        return 1
    
    arr = []
    
    for i in lines:
        tmp = i.split(" ")
        T_sec = float(tmp[2][:-1])
        end_time = int(tmp[1][:2])*3600000 + int(tmp[1][3:5])*60000 + int(tmp[1][6:8])*1000 + int(tmp[1][-3:])
        start_time = end_time - T_sec*1000 + 1
        
        arr.append((end_time,-1))
        arr.append((start_time,1))
    
    arr = sorted(arr)
    
    
    
    count = 0
    cnt_arr = []
    
    intersect = 0
    num_of_bar = 0
    
    print(arr)
                
    for i in range(len(arr)):
        if arr[i][0] < 0:
            continue
        if arr[i][1] == -1:
            num_of_bar -= 1
            count += 1
        else:
            num_of_bar+= 1
        duration_time = arr[i][0] + 999
        for j in range(i,len(arr)):
            if arr[j][0] > duration_time:
                #print(arr[j])
                break
            if arr[j][0] <= duration_time and arr[j][1] == 1:
                #print(arr[j])
                count += 1
        count += num_of_bar        
        cnt_arr.append(count)
        count = 0
            
    print(cnt_arr)
        
        
    if max(cnt_arr) != 1:
        return max(cnt_arr)-1
    else:
        return max(cnt_arr)
        
        
        
        
    
    
    
    
    return answer

63%의 정확도

def solution(lines):
    answer = 0
    
    if len(lines) == 1:
        return 1
    
    arr = []
    
    len_num = 0
    
    for i in lines:
        tmp = i.split(" ")
        T_sec = float(tmp[2][:-1])
        end_time = int(tmp[1][:2])*3600000 + int(tmp[1][3:5])*60000 + int(tmp[1][6:8])*1000 + int(tmp[1][-3:])
        start_time = end_time - T_sec*1000 + 1
        
        arr.append((end_time,-1,len_num))
        arr.append((start_time,1,len_num))
        len_num += 1
    
    arr = sorted(arr)
    
    count = 0
    cnt_arr = []
    arr2 = [0]*len_num
    for i in range(len(arr)):
        
        count += sum(arr2)
        
        if arr[i][1] == 1:
            arr2[arr[i][2]] = 1
        else:
            arr2[arr[i][2]] = 0
        
        if arr[i][0] < 0:
            continue
        
        duration_time = arr[i][0] + 999
        
        for j in range(i,len(arr)):
            if arr[j][0] > duration_time:
                break
                
            if arr[j][1] == 1:
                count += 1   
                
        cnt_arr.append(count)
        count = 0
        
        
    return max(cnt_arr)
반응형
반응형

1. flask 설치

 

# Flask 설치
$ pip install flask

# Flask 확인
$ flask --version

 

2. test 폴더 하나 만들고 들어가서 app.py 파일 만들어준다.

 

app.py

from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    return 'Hello Flask'
    
@app.route('/info')
def info():
    return 'Info'

 

Flask 서버 구동 확인하기

콘솔창에서 아래의 명령어 입력한다.

flask run

 

http://127.0.0.1:5000/ 로 들어가면 확인할 수 있다.

 

 

 

템플릿 추가하기

pyflask 폴더 내에 templates 폴더를 추가하고, index.html과 info.html 파일을 추가한다.

 

app.py에 템플릿 코드 추가

from flask import Flask, render_template
app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')
    
@app.route('/info')
def info():
    return return render_template('info.html')

 

 

templates/index.html

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Flask Index</title>
</head>
<body>

<h1>Hello Flask</h1>
<p>This page is for Flask tutorial.</p>

</body>
</html>

templates/info.html

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Flask Info</title>
</head>
<body>

<p>This page is Info page.</p>

</body>
</html>

추가된 페이지 확인

app.py의 router를 통해 http://127.0.0.1:5000/과 http://127.0.0.1:5000/info/에 접속하면 index.html과 info.html를 확인할 수 있다.

 

 

 

위의 글은

https://velog.io/@decody/%ED%8C%8C%EC%9D%B4%EC%8D%AC-Flask%EB%A1%9C-%EA%B0%84%EB%8B%A8-%EC%9B%B9%EC%84%9C%EB%B2%84-%EA%B5%AC%EB%8F%99%ED%95%98%EA%B8%B0

다음의 블로그를 똑같이 따라해보았습니다.!

반응형
반응형

1. Jython 설치

 

아래의 링크에서 들어가서 Jython Installer를 다운 받는다.

https://www.jython.org/download

Downloads

The Python runtime on the JVM

www.jython.org

 

2. 다운로드 받고 아래의 명령어를 실행해준다.

java -jar jython-installer-2.7.2.jar

 

물론 jar파일이 있는 위치에서 실행해주어야 한다. 

 

 

3. mvn에 등록을 해주기 위해 아래의 명령어를 실행해준다.

 

mvn install:install-file -Dfile=[파일 full경로] -DgroupId=[그룹아이디] -DartifactId=[artifactId] -Dversion=[버전정보] -Dpackaging=[jar] -DgeneratePom=true

mvn install:install-file -Dfile=자이썬파일위치/jython-installer-2.7.2.jar -DgroupId=com.neo -DartifactId=myutil -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true

 

4. 등록이 되었다면

정상적으로 됐다면 아래와 같은 경로로 폴더가 생성되고 해당 jar 파일과 *.pom 파일이 만들어진 것을 확인할 수 있다.
C:\Users\Administrator\.m2\repository\com\neo\myutil\1.0
myutil-1.0.jar
myutil-1.0.pom

 

사용은 마찬가지로 pom.xml 에 추가해주면 된다.

  <dependency>
   <groupId>com.neo</groupId>
   <artifactId>myutil</artifactId>
   <version>1.0</version>
  </dependency>

 


출처: https://neoguru.tistory.com/18 [memory note]

 

 

이렇게 하고 사용하면 된다.

반응형
반응형

OMP: Error #15: Initializing libiomp5.dylib, but found libiomp5.dylib already initialized 

에러 발생!

 

 

아래의 코드라인을 추가해준다.

import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'
반응형

'IT' 카테고리의 다른 글

python - flask 웹 서버 구축하기  (0) 2020.05.05
Jython 사용방법  (0) 2020.05.05
Python cv2 설치  (0) 2020.05.02
AWS 기초 예제- 인스턴스 만들기  (0) 2020.05.01
expo.io를 활용한 클라이언트 앱  (0) 2020.05.01

+ Recent posts