Stack2 [C] Stack 구현 (non -Circular) [C] Stack 구현 (non -Circular) - Code #include #define MAX_SIZE 10 void push(int data); int pop(); int stack_full(); int stack_empty(); int stack[MAX_SIZE] = {}; int top = -1; int main(){ int want= 0; //operation number int input = 0; //input data while (1) { printf("What do you want? 1.push 2.pop 3.end :"); scanf_s("%d", &want); switch (want) { case 1: if (stack_full()) // is stack full? printf(".. 2022. 3. 14. [HackerRank] Equal stacks [HackerRank] Equal stacks 문제 링크 https://www.hackerrank.com/challenges/equal-stacks/problem?isFullScreen=true 시간복잡도: O(n) 코드 def equalStacks(h1, h2, h3): sumH1 = sum(h1) sumH2 = sum(h2) sumH3 = sum(h3) while 1: minNum=min(sumH1, sumH2, sumH3) if(sumH1==sumH2==sumH3): #equal? break if(sumH1 > minNum): #sum > min? sumH1 -= h1.pop(0) if(sumH2 > minNum): sumH2 -= h2.pop(0) if(sumH3 > minNum): sumH3 -.. 2022. 3. 8. 이전 1 다음