전체 글 (306)
2022-01-06 20:28:27
반응형

1. SQL DEVELOPER 설치본 실행 또는 우클릭하여 관리자 권한으로 실행

 

2. 환경설정 임포트 확인 팝업창이 뜨면 '아니오(N)' 버튼 마우스로 클릭

3. SQL DEVELOPER 설치 진행

4.  Oracle Usage Tracking 팝업창 발생 시 확인 버튼 마우스로 클릭

- Allow automated uasage reporting to Oracle 체크 여부 상관없음

5. Oracle SQL Developer 프로그램 실행 이후 Oracle DB 관리자 계정 연동 진행

접속 이름 (N) : 관리자
사용자 이름 (U) : system
비밀번호 (P) : *******
비밀번호 저장 체크

6. 계정 정보 입력 완료 후 테스트 버튼 클릭 → 상태 : 성공 메시지 확인

7. 저장 버튼 마우스로 클릭 → 관리자 계정 연동 여부 확인

반응형
2022-01-06 20:07:40
반응형

1.

Install 버튼 마우스로 클릭

 

Finish 버튼 마우스로 클릭

 

반응형
2022-01-05 00:03:32
반응형

Same Tree

 

 문제 설명

 

Given the roots of two binary trees p and q, write a function to check if they are the same or not.

Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.

 

 제한 사항

 

  • The number of nodes in both trees is in the range [0, 100].
  • -104 <= Node.val <= 104

 

 입출력 예

 

input output
p = [1, 2, 3] , q = [1, 2, 3] True
p = [1, 2] , q = [1, null, 3] False
p = [1, 2, 1] , q = [1, 1, 2] False

 

 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)
  • isSameTree( )는 왼쪽의 서브 트리와 오르른쪽의 서브트리가 동일한지를 판단하는 재귀함수

* 참고 링크 : https://velog.io/@wisepine/Leetcode-Same-Tree

 

 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/same-tree/discuss/166896/C++-solution-beats-100

 

 출처

 

https://leetcode.com/problems/same-tree/submissions/

반응형
2022-01-04 23:13:28
반응형

Palindrome Number

 

 문제 설명

 

Given an integer x, return true if x is palindrome integer.

An integer is a palindrome when it reads the same backward as forward.

  • For example, 121 is a palindrome while 123 is not.

 

 제한 사항

 

  • -231 <= x <= 231 - 1

 

 입출력 예

 

x return
121 True
-121 False
10 False

 

 Python 코드

 

  • int를 문자열로 변환

 

135ms code Python

class Solution:
    def isPalindrome(self, x: int) -> bool:
        return str(x) == str(x)[::-1]

 

56ms code Python

class Solution:
    def isPalindrome(self, x: int) -> bool:
        return False if x < 0 else str(x) == str(x)[::-1]

 

* 참고 링크 1 : https://hackmd.io/@y56/Hk6PWb7mr?type=view 

* 참고 링크 2 : https://dhairya2136.medium.com/leetcode-9-palindrome-number-python-bdcd99bd7068

 

* Python Array [ :: ] 용법

arr[::], arr[1:2:3], arr[::-1] 등으로 배열의 index에 접근하는 방법을 Extended Slices(확장형 슬라이스)라고 한다.

arr[A:B:C]의 의미는, index A 부터 index B 까지 C의 간격으로 배열을 만들어라는 말입니다.
- A가 None 이라면, 처음부터 라는 뜻
- B가 None 이라면, 할 수 있는데까지
- C가 양수라면 마지막 index까지, C가 음수라면 첫 index까지가 된다.
- 마지막으로 C가 None 이라면 한 칸 간격으로 라는 뜻
arr = range(10) 
arr 
# result : [0,1,2,3,4,5,6,7,8,9] 

arr[::2] # 처음부터 끝까지 두 칸 간격으로 
# result : [0,2,4,6,8] 

arr[1::2] # index 1 부터 끝까지 두 칸 간격으로 
# result : [1,3,5,7,9] 

arr[::-1] # 처음부터 끝까지 -1칸 간격으로 ( == 역순으로) 
# result : [9,8,7,6,5,4,3,2,1,0] 

arr[::-2] # 처음부터 끝까지 -2칸 간격으로 ( == 역순, 두 칸 간격으로) 
# result : [9,7,5,3,1] 

arr[3::-1] # index 3 부터 끝까지 -1칸 간격으로 ( == 역순으로) 
# result : [3,2,1,0] 

arr[1:6:2] # index 1 부터 index 6 까지 두 칸 간격으로 
# result : [1,3,5]

* 참고 링크 1 : https://blog.wonkyunglee.io/3

* 참고 링크 2 : https://docs.python.org/release/2.3.5/whatsnew/section-slices.html

* is_palindrome ( ) 함수 : 회문 판별 함수

palindrome(회문)은 순서를 거꾸로 읽어도 제대로 읽은 것과 같은 단어와 문장을 의미한다.
예를 들어 "level", "SOS", "rotator", "nurses run"과 같은 단어와 문장이 있다.
def is_palindrome(word):
    return word[::-1]==word

# True
print( is_palindrome("kayak") )
print( is_palindrome("madam") )
print( is_palindrome("racecar") )
print( is_palindrome("abradacadarba") )
print( is_palindrome("토마토") )

# False
print( is_palindrome('hello') )
print( is_palindrome('coffee') )

* 참고 링크 1 : https://zetawiki.com/wiki/%ED%95%A8%EC%88%98_is_palindrome() 

* 참고 링크 2 : https://dojang.io/mod/page/view.php?id=2331 

 

 C++ 코드

 

class Solution {
public:
    bool isPalindrome(int x) {
        string temp = std::to_string(x);
        int left = 0;
        int right = temp.size()-1;
        while(left<=right)
        {
            if(temp[left++]!=temp[right--])
                return false;
        }
        return true;
    }
};

 

C ++ 100% 0ms code

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

 class Solution {
public:
    bool isPalindrome(int x) {
        int temp = x;
        long rev, rem;
        rev = 0;
        
        if (x < 0)
            return false;
        
        while (temp != 0){
            rem = temp % 10;
            rev = rev * 10 + rem;
            temp = temp/10;
        }
        
        if (x == rev)
            return true;
        else
            return false;
    }
};

* 참고 링크 : https://kkminseok.github.io/posts/leetcode_Palindrome_Number/

 

 출처

 

https://leetcode.com/problems/palindrome-number/

 

반응형
2022-01-04 00:33:48
반응형

N개의 최소공배수

 

 문제 설명

 

두 수의 최소공배수(Least Common Multiple)란 입력된 두 수의 배수 중 공통이 되는 가장 작은 숫자를 의미합니다. 예를 들어 2와 7의 최소공배수는 14가 됩니다. 정의를 확장해서, n개의 수의 최소공배수는 n 개의 수들의 배수 중 공통이 되는 가장 작은 숫자가 됩니다. n개의 숫자를 담은 배열 arr이 입력되었을 때 이 수들의 최소공배수를 반환하는 함수, solution을 완성해 주세요.

 

 제한 사항

 

  • arr은 길이 1이상, 15이하인 배열입니다.
  • arr의 원소는 100 이하인 자연수입니다.

 

 입출력 예

 

arr return
[2, 6, 8, 14] 168
[1, 2, 3] 6

 

 Python 코드

 

import math

def solution(num):
    answer = num[0]
    for n in num:
        answer = (n * answer) // math.gcd(n, answer)
    return answer
  • 최대공약수 gcd는 math.gcd를 이용해 구해주고,
     
    최소공배수 lcm은 A * B // gcd(A,B) 이므로 for문을 돌면서 맨 마지막 answer를 return 해주면 된다.

* 참고 링크 : https://wookcode.tistory.com/101

def solution(arr):
    answer = 0
    max_num = 1
    for a in arr:
        max_num *= a
    
    for i in range(2, max_num+1):
        for a in arr:
            if i%a != 0:     # 나누어 떨어지지 않는다면 break
                break
                             # 위에서 break에 걸리지 않았다면 
                             # 모두 나누어 떨어지는 것이기 때문에 해당 i를 answer에 대입
        else:
            answer = i
            break
    return answer

* 참고 링크 : https://kimmeh1.tistory.com/190

 C++ 코드

 

#include <string>
#include <vector>

using namespace std;
int GCD(int a, int b){         // 최대공약수
    if(a == 0) return b;
    return GCD(b % a, a);
}
int LCM(int a, int b){         // 최소공배수
    return a * b / GCD(a,b);
}
int solution(vector<int> arr) {
    int answer = 0;
    answer = arr[0];
    for(int i=1;i<arr.size();i++){
        answer = LCM(answer, arr[i]);
    }
    return answer;
}
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int gcd(int x, int y) { return x % y == 0 ? y : gcd(y, x % y); }
int lcm(int x, int y) { return x * y / gcd(x, y); }
int solution(vector<int> arr) {
    int answer = arr[0];
    for (int i = 1; i < arr.size(); i++)
        answer = lcm(answer, arr[i]);
    return answer;
}

 

반응형
2022-01-04 00:18:12
반응형

문자열 다루기 기본

 

 문제 설명

 

문자열 s의 길이가 4 혹은 6이고, 숫자로만 구성돼있는지 확인해주는 함수, solution을 완성하세요. 예를 들어 s가 "a234"이면 False를 리턴하고 "1234"라면 True를 리턴하면 됩니다.

 

 제한 사항

 

  • s는 길이 1 이상, 길이 8 이하인 문자열입니다.

 

 입출력 예

 

s return
"a234" false
"1234" true

 

 Python 코드

 

def solution(s):

    if (len(s) == 4 or len(s) == 6) and s.isdigit():
        return True
    else:
        return False

 

* 참고 링크 : https://jeongchul.tistory.com/651

* isdigit ( ) 함수 : 문자열이 숫자로만 이루어져 있는지 확인하는 함수

- 문자가 단 하나라도 있다면 False를 반환하고, 모든 문자가 '숫자'로만 이루어져 있으면 True를 반환한다.

isdigit ( ) 함수는 string 클래스에 있는 메서드이다. 즉, 문자열.isdigit( ) 형태로 사용하는 메서드이다.

ex) str.isdigit()

a = "CodingTest" # 문자로만 이루어짐
b = "은하철도999" # 문자 + 숫자
c = "-999"       # 음수
d = "3.14"       # 소수점
e = "2022"       # 숫자

print(f"str.isdigit('{a}') : {str.isdigit(a)}")
print(f"str.isdigit('{b}') : {str.isdigit(b)}")
print(f"str.isdigit('{c}') : {str.isdigit(c)}")
print(f"str.isdigit('{d}') : {str.isdigit(d)}")
print(f"str.isdigit('{e}') : {str.isdigit(e)}")

print()

print(f"'{a}'.isdigit() : {a.isdigit()}")
print(f"'{b}'.isdigit() : {b.isdigit()}")
print(f"'{c}'.isdigit() : {c.isdigit()}")
print(f"'{d}'.isdigit() : {d.isdigit()}")
print(f"'{e}'.isdigit() : {e.isdigit()}")

 

 

* len() 함수 : 매개변수로 들어온 문자열의 길이를 반환

- 내부에 있는 문자의 갯수 및 공백을 포함한 카운팅을 하여 반환해주는 함수

- 문자열의 길이를 구할 때 용이

 
strlen = "HelloWorld"
 
print(len(strlen))
 
 
 
# 결과값 10

 

 C++ 코드

 

#include <string>
#include <vector>
//#include <cctype>
 
using namespace std;
 
bool solution(string s) 
{
    //1. 길이로 쳐낸다.
    const size_t length = s.length();
    if(length != 4 && length != 6)
    {
        return false;
    }
 
    //2. 문자가 있으면 쳐낸다.
    for(size_t i=0; i<length; ++i)
    {
        //if(!isdigit(s[i]))
        if(!(s[i] >= '0' && s[i] <= '9'))
        {
            return false;
        }
    }
 
    return true;
}

* 참고 링크 : https://blockdmask.tistory.com/280

반응형