전체 글 (261)
2022-01-13 23:33:17
반응형

Pascal's Triangle

 

 문제 설명

 

Given an integer numRows, return the first numRows of Pascal's triangle.

In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:

 

 제한 사항

 

  • 1 <= numRows <= 30

 

 입출력 예

 

Example 1:

Input : numRows = 5
Output : [[1], [1.1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]

Example 2:

Input : numRows = 1
Output : [[1]]

 

 Python 코드

 

Python 8ms code 

# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right

class Solution(object):
    def isSameTree(self, p, q):
     
        if not p and not q:
            return True
        if not p or not q:
            return False
        
        return p.val == q.val and self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
  •  

* 참고 링크 : 

 

 C++ 코드

 

C ++ 100% 0ms code

- String으로 바꾸지 않고 맨 뒤의 값과 맨 앞의 값을 비교하면서 푼 코드

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    bool isSameTree(TreeNode* p, TreeNode* q) {
        if(p == NULL && q == NULL) // if the two nodes are empty nodes, return true
            return true;
        else if((p == NULL && q != NULL) || (p != NULL && q == NULL)) // if only one of the nodes from p and q is emtpy, 2 trees are not equal
            return false;
        else 
            return p->val == q->val && isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
						// First we compare the values in each node from p and q. Then, use a recursive method, call isSameTree function with left nodes of p and q as parameters. Do the same for the right nodes.
    }
};

* 참고 링크 : 

 

 출처

 

https://leetcode.com/problems/pascals-triangle/

반응형
2022-01-13 23:30:50
반응형

3Sum

 

 문제 설명

 

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.

 

 제한 사항

 

  • 0 <= nums.length <= 3000
  • -105 <= nums[i] <= 105

 

 입출력 예

Example 1:

Input : num = [-1, 0, 1, 2, -1, -4]
Output : [[-1, -1, 2], [-1, 0, 1]]

Example 2:

Input : nums = []
Output : []

Example 3:

Input : nums = [0]
Output : []

 

 Python 코드

 

Python 8ms code 

# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right

class Solution(object):
    def isSameTree(self, p, q):
     
        if not p and not q:
            return True
        if not p or not q:
            return False
        
        return p.val == q.val and self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
  •  

* 참고 링크 : 

 

 C++ 코드

 

C ++ 100% 0ms code

- String으로 바꾸지 않고 맨 뒤의 값과 맨 앞의 값을 비교하면서 푼 코드

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    bool isSameTree(TreeNode* p, TreeNode* q) {
        if(p == NULL && q == NULL) // if the two nodes are empty nodes, return true
            return true;
        else if((p == NULL && q != NULL) || (p != NULL && q == NULL)) // if only one of the nodes from p and q is emtpy, 2 trees are not equal
            return false;
        else 
            return p->val == q->val && isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
						// First we compare the values in each node from p and q. Then, use a recursive method, call isSameTree function with left nodes of p and q as parameters. Do the same for the right nodes.
    }
};

* 참고 링크 : 

 

 출처

 

https://leetcode.com/problems/3sum/

 

반응형
2022-01-13 23:25:27
반응형

Add Two Numbers

 

 문제 설명

 

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

 

 제한 사항

 

  • The number of nodes in each linked list is in the range [1, 100].
  • 0 <= Node.val <= 9
  • It is guaranteed that the list represents a number that does not have leading zeros.

 

 입출력 예

 

Example 1:

Input : l1 = [2, 4, 3], l2 = [5, 6, 4]
Output : [7, 0, 8]
Explanation : 342 + 465 = 807

Example 2:

Input : l1 = [0], l2 = [0]
Output : [0]

Example 3:

Input : l1 = [9, 9, 9, 9, 9, 9, 9], l2 = [9, 9, 9, 9]
Output : [8, 9, 9, 9, 0, 0, 0, 1]

 

 Python 코드

 

Python 8ms code 

dd
  •  

* 참고 링크 : 

 

 C++ 코드

 

C ++ 100% 0ms code

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */

* 참고 링크 : 

 

 출처

 

https://leetcode.com/problems/add-two-numbers/

반응형
2022-01-12 23:34:53
반응형

DBMS (DataBase Management System, 데이터베이스 관리 시스템) 

DBMS (DataBase Management System, 데이터베이스 관리 시스템)는 다수의 사용자들이 DataBase 내의 Data를 접근할 수 있도록 해주는 소프트웨어 도구의 집합

 DBMS 장점

 

  • Data의 접근성 용이
  • Data Control 강화
  • Application Program들을 쉽게 개발하고 관리할 수 있다.
  • 보안 강화

 

 DataBase File Architecture(데이터베이스 파일 구조)

 

DataBase File Architecture(데이터베이스 파일구조)는 위의 그림과 같이 논리영역과 물리영역으로 나누어서 볼 수 있다.

물리적으로 디스크에는 DataBase(데이터베이스)가  여러 개의 Data File로 구성되어 있다.

각각의 Data File은 여러 개의 Block 단위로 구성되어 있다.

ex) TableSpace(땅) - Segment(건물) - Extent(건물의 한 층) - Block(건물 한 층의 사무실)

  • Block

Oracle DB에서의 Block은 최소 단위 (KB)

  • Extent

- 여러 개의 Block의 집합 (Block을 묶음)

- I/O 단위는 Block이지만  Table Space로부터 공간을 할당하는 단위는 Extent이다.

  • Segment

- 여러 개의 Extent를 가지고 있는 Object이다.

- DataBase의 Table, Index, Undo처럼 저장공간이 필요로 하는 Object를 말한다.

* Undo Data : DML(Data Manipulation, 데이터 조작어)이 발생할 경우 변경되기 전의 Data 값

  • Table Space

- Segment를 담는 컨테이너로 여러 Data File로 구성

  • *.dbf

- Oracle DB 확장자 (DataBase File)

 

 출처

 

* DBMS 정의 및 장점 : https://ko.wikipedia.org/wiki/%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%B2%A0%EC%9D%B4%EC%8A%A4_%EA%B4%80%EB%A6%AC_%EC%8B%9C%EC%8A%A4%ED%85%9C

* 디스크 영역 / 데이터 파일 구조 : https://jeong-pro.tistory.com/147

* Undo Data : 

http://wiki.gurubee.net/display/STUDY/1st_Undo

https://m.blog.naver.com/0325han/221190462093

+ 강의 교재

반응형
2022-01-12 22:50:28
반응형

 

DataBase (데이터 베이스)란?

DataBase (데이터 베이스)는 많은 사람들이 공유해서 사용할 목적으로 통합 관리되는 정보(Data)의 집합을 의미

 

 DataBase (데이터 베이스) 특징

 

  • Shared Data (공용 데이터)

- 여러 사용자들이 서로 다른 목적으로 공유하여 사용되는 Data를 의미

 

  • Integrated Data (통합 데이터)

- Data를 통합하여 Data 중복 제거 및 효율적으로 Data 관리가 가능

 

  • Stroed Data (저장 데이터)

- 중요한 Data는 삭제되지 않고 보존되도록 관리되어야 한다.

- 컴퓨터가 접근할 수 있는 디스크와 같은 저장 매체 & 저장소에 저장되어 휘발성이 아닌 영속성을 갖는다.

 

  • Operational Data (운영 데이터)

- 반드시 필요한 Data를 저장하는 것

- 불필요하게 Data를 저장하고 끝나는 것이 아니고 실제로 유용하게 사용할 수 있는 관리 목적으로 명확한 Data를 의미

 

 출처

 

https://wikidocs.net/3901

 

+ 강의 교재

반응형
2022-01-11 08:45:41
반응형

정수 제곱근 판별

 

 문제 설명

 

임의의 양의 정수 n에 대해, n이 어떤 양의 정수 x의 제곱인지 아닌지 판단하려 합니다.
n이 양의 정수 x의 제곱이라면 x+1의 제곱을 리턴하고, n이 양의 정수 x의 제곱이 아니라면 -1을 리턴하는 함수를 완성하세요.

 

 제한 사항

 

  • n은 1이상, 50000000000000 이하인 양의 정수입니다.

 

 입출력 예

 

n return
121 144
3 -1

 

 Python 코드

 

from math import sqrt

def solution(n):
    return int(sqrt(n) + 1) ** 2 if sqrt(n) % 1 == 0 else -1

* 참고 링크 : https://velog.io/@cosmos/Programmers%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EC%A0%95%EC%88%98-%EC%A0%9C%EA%B3%B1%EA%B7%BC-%ED%8C%90%EB%B3%84-python

def solution(n):
    answer = 0
    num = n ** 0.5

    if num == int(num):
        answer = (num+1) ** 2
    else:
        answer = -1

    return answer

* 참고 링크 : https://jokerldg.github.io/algorithm/2021/04/14/int-sqrt.html

 

 C++ 코드

 

#include <string>
#include <vector>
#include <cmath>
using namespace std;

long long solution(long long n) {
	if (sqrt(n) - (int)sqrt(n) == 0) // n이 정수의 제곱인 경우
		return (sqrt(n) + 1) * (sqrt(n) + 1);
	return -1;
}

 

* 참고 링크 : https://greenapple16.tistory.com/129

 

 출처

 

https://programmers.co.kr/learn/courses/30/lessons/12934

반응형