본문 바로가기

Programming5

[LeetCode] 13. Romans to Integer (Python) Problem Roman to Integer - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 말그대로 로마어를 숫자로 바꾸는 프로그램이다. 문제를 이해하는 것에는 어렵지 않았고 문자어로 쓰여있는 것을 각각 숫자로 변환하여 더해주면 되는 듯한 간단한 문제라고 생각이 되었다. -> 하지만 단순히 이런 방식을 꾀하면 VI(6)와 IV(4)의 차이가 없어진다. 따라서 뒤에 큰 숫자가 오면 (큰 수 - 작은 수)의 방법을 취해야 하는 것을 알 수 있다. 어떻게 풀어야 .. 2022. 4. 9.
[LeetCode] 9. Palindrome Number (python) Palindrome Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Problem 오늘의 문제는 Palinedrome Number을 판별하는 코드를 작성하는 것이다. Palinedrome 숫자란 121처럼 앞뒤를 바꿔도 똑같은 (전화번호 아님) 숫자를 말한다. 이 문제에서 주의해야 할 것은 음의 정수가 포함된다는 것이다! -121을 바꿔면 121-이므로 Palinedrome 숫자가 아니다. (설명도 적어야 한다.) First Try: Wrong A.. 2022. 4. 9.
[HackerRank] PlusMinus (python) Given an array of integers, calculate the ratios of its elements that are positive, negative, and zero. Print the decimal value of each fraction on a new line with places after the decimal. Note: This challenge introduces precision problems. The test cases are scaled to six decimal places, though answers with absolute error of up to are acceptable. Example There are elements, two positive, two n.. 2022. 4. 9.
[LeetCode] 1046. Last Stone Weight 1 Day 1 Commit Challenge! 오늘은 리트코드의 last stone weight 를 풀어보았다. 아직 파이썬에 익숙하지 않아 다양한 함수를 불러오는 데에 어려움이 많다. Last Stone Weight - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 리트 코드의 Easy 단계의 문제들을 계속 풀어나갈 예정이다. 해답은 이렇게 ... class Solution(object): def lastStoneWeight(self, stones): """ .. 2022. 4. 8.
[HackerRank] Diagonal Difference (python) #!/bin/python3 import math import os import random import re import sys # # Complete the 'diagonalDifference' function below. # # The function is expected to return an INTEGER. # The function accepts 2D_INTEGER_ARRAY arr as parameter. # def diagonalDifference(arr): # Write your code here left = 0 right = 0 for i in range(len(arr)): left += arr[i][i] right += arr[i][len(arr)-i-1] return abs(left .. 2022. 4. 7.