본문 바로가기

분류 전체보기351

[leetcode 29] Divide Two Integers Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero, which means losing its fractional part. For example, truncate(8.345) = 8 and truncate(-2.7335) = -2. Note: Assume we are dealing with an environment that could only store in.. 2020. 11. 13.
[leetcode 14] Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Example 1: Input: strs = ["flower","flow","flight"] Output: "fl" Example 2: Input: strs = ["dog","racecar","car"] Output: "" Explanation: There is no common prefix among the input strings. Constraints: 0 2020. 11. 13.
[백준 16987] 계란으로 계란치기 www.acmicpc.net/problem/16987 16987번: 계란으로 계란치기 원래 프로그래머의 기본 소양은 팔굽혀펴기를 단 한 개도 할 수 없는 것이라고 하지만 인범이는 3대 500을 넘기는 몇 안되는 프로그래머 중 한 명이다. 인범이는 BOJ에서 틀린 제출을 할 때마다 턱 www.acmicpc.net n의 범위가 1부터 8까지이기 때문에 브루트 포스 & 백트래킹을 하면 풀리는 문제이다. 주의할 점: hand== n인 기저조건까지 도달하기 위해 모든 조건에서 backtracking함수를 실행시켜야 한다는 것이다. ' ++괜히 경우의 수를 출력한다고 했다가 너무 많은 경우의 수라서 무한 루프 도는 것처럼 보였다... #include #include #define MAX 8 //n=8이기 때문에 다.. 2020. 11. 12.
[leetcode 34] Find First and Last Position of Element in Sorted Array Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. Follow up: Could you write an algorithm with O(log n) runtime complexity? Example 1: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3,4] Example 2: Input: nums = [5,7,7,8,8,10], target = 6 Output: [-1,-1] Example 3: Inp.. 2020. 11. 12.