- 그리디 알고리즘 * 그리디 알고리즘(탐욕법)은 현재 상황에서 지금 당장 좋은것만 고르는 방법 * 코딩테스트에서의 대부분의 그리디 문제는 탐욕법으로 얻은 해가 최적의 해가되는 상황에서, 이를 추론할 수 있어야 풀리도록 출제 됩니다. 거스름돈 문제 - 카운터에는 거스름돈으로 사용할 500, 100, 50, 10원 짜리 동전이 무한히 존재한다고 가정할때 손님에게 거슬러주어야할 동전의 최소 갯수구하시오. 거슬러주어야할돈 N , N은 항상 10의 배수 1. 최적의 해를 빠르게 구하기 위해서는 가장 큰 화폐단위부터 거슬러준다. n = 1260 count = 0 array = [500, 100, 50, 10] for coin in array : count += n // coin#나누기 n = n%coin#나머지 print(count.. 2021.10.28
- Docker 컨테이너에서 자바 Thread, Heap dump 파일 생성하기 1. 덤프를 원하는 컨테이너로 접속 docker exec -it {hash} bash 2. 아래 명령어로 java PID확인 root@bf342a25fc61:/# ps -fea|grep -i java 3. 덤프뜨기 root@bf342a25fc61:/# jstack PID > thread.tdump #Thread dump root@bf342a25fc61:/# jmap -dump:live,format=b,file=heap.hprof PID #heap dump ls를 쳐서 잘 생성되었는지 확인한다 4. 컨테이너 탈출 root@bf342a25fc61:/# exit 5. 컨테이너 안에 있는 dump파일 옮기기 docker cp bf342a25fc61:/thread.tdump . https://iceburn.med.. 2021.10.27
- [leetcode Easy] 771. Jewels and Stones 문자열, 해시테이블 You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels. Letters are case sensitive, so "a" is considered a different type of stone from "A". Example 1: Input: jewels = "aA", stones = "aAAbbbb" Output: 3 Example .. 2021.10.27
- 쉘스크립트 CPU임계치에 따른 라인톡보내기 운영중이던 서버가 갑자기 cpu임계치를 넘어버리며 죽어버리던 현상이 발생했다 그래서 자주 모니터링을 해주며 대처를 해줘야했는데 계속 보고 앉아있을수 없으니 이용중이던 azure 파트너사를 통해 알림 연동을 해달라고 하니 추석 지나서 해줄수있다는 말에 급하게 스크립트를 작성했다. #!/bin/bash s_time=$(date +%Y-%m-%d' '%H:%M:%S) PREV_TOTAL=0 PREV_USER=0 while true; do CPU=(`cat /proc/stat | grep '^cpu '`) unset CPU[0] USER=${CPU[1]} # Calculate the total CPU time. TOTAL=0 for VALUE in "${CPU[@]}"; do let "TOTAL=$TOTAL+$.. 2021.10.27
- [같은 수 찾기] 1512. Number of Good Pairs Given an array of integers nums, return the number of good pairs. A pair (i, j) is called good if nums[i] == nums[j] and i int: res = 0 for i in range(len(nums)) : for j in range(i, len(nums)) : if i != j : if nums[i] == nums[j] : res += 1 return res O(n2) 시간복잡도 최악ㅋ 고인물의 솔루션 더보기 def numIdenticalPairs(self, A): return sum(k * (k - 1) / 2 for k in collections.Counter(A).values()) def numIdenticalP.. 2021.10.26