Git Product home page Git Product logo

algorithms's Issues

time(str) to int, int to time(str)

문자열로 된 시간을 '초'단위로 바꾸기
HH:MM:SS => 초로 바꾸기

def str_to_int(time):
    h, m, s = time.split(':')
    return int(h) * 3600 + int(m) * 60 + int(s)
   
            
def int_to_str(time):
    h = time // 3600
    h = '0' + str(h) if h < 10 else str(h)
    time = time % 3600
    m = time // 60
    m = '0' + str(m) if m < 10 else str(m)
    time = time % 60
    s = '0' + str(time) if time < 10 else str(time)
    return h + ':' + m + ':' + s

PyPy3 vs. Python3

PyPy3는 기본적으로 Python3와 동일한 문법을 지원하지만
코어적으로 더욱 빠르게 동작한다는 이유로 PyPy3의 사용을 추천하는데,
메모리 사용량이 파이썬3보다 많다는 점을 고려하여 푸는 문제의 종류에 따라 잘 선택해야함

시간 효율성 => PyPy3이 좋음
메모리 효율성 => Python3이 좋음

재귀 한도 늘려주기

재귀함수 사용시 런타임 에러 -> 다음 코드로 해결

import sys
sys.setrecursionlimit(10**6)

벨만포드 알고리즘 - INF를 주의하자

음수 가중치가 있다면?! => 다익스트라가 아닌 벨만포드를 사용하자..
단! Complexity는 주의! => O(EV)이므로 노드, 간선 개수가 작을때 사용

이 때, INF 변수를 int가 아닌 아래처럼 사용해야 distance 존재 여부 등 판단 시 스무스하게 해결됨

INF = float('inf')  # 이렇게 사용해야함

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.