분류 전체보기
-
Sparse Arrays해커랭크(HackerRank) 2018. 8. 19. 17:24
1. 문제입력 받은 스트링 벡터 요소에서 같은 문자가 있다면 총 같은 문자의 개수를 출력 하는 문제 2. 알고리즘키워드 - 구현, 문자열 3. 코드 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556#include using namespace std; /* * Complete the findSuffix function below. */int findSuffix(vector collections, string queryString) { /* * Write your code here. */ const int size = collections.size(); int sol = 0..
-
Print the Elements of a Linked List해커랭크(HackerRank) 2018. 8. 19. 17:23
1. 문제 2. 알고리즘키워드 - 구현, 출력 3. 코드 123456789101112131415161718192021/* Print elements of a linked list on console head pointer input could be NULL as well for empty list Node is defined as struct Node { int data; struct Node *next; }*/void Print(Node *head){ if(!head) return ; // This is a "method-only" submission. // You only need to complete this method. if(head->data) cout
-
Insert a Node at the Tail of a Linked List해커랭크(HackerRank) 2018. 8. 19. 17:22
1. 문제 2. 알고리즘키워드 - 구현, 링크리스트 3. 코드 123456789101112131415161718192021222324252627/* Insert Node at the end of a linked list head pointer input could be NULL as well for empty list Node is defined as struct Node { int data; struct Node *next; }*/Node* Insert(Node *head,int data){ // Complete this method Node* node = new Node(); node->data = data; node->next = NULL; if (head == NULL) { head = node;..
-
Maximum Element해커랭크(HackerRank) 2018. 8. 19. 17:21
1. 문제 2. 알고리즘키워드 - 구현, 스택 3. 코드 12345678910111213141516171819202122232425262728293031323334353637383940#include #include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ stack s, m; m.push(-1); int n; cin>>n; int i = 0; while(i>x; if(x==1) { int z ;cin>>z; s.push(z); if(z >= m.top()) m.push(z); } else ..
-
Print in Reverse해커랭크(HackerRank) 2018. 8. 19. 17:20
1. 문제 2. 알고리즘키워드 - 구현, 출력 3. 코드 12345678910111213141516171819/* Print elements of a linked list in reverse order as standard output head pointer could be NULL as well for empty list Node is defined as struct Node { int data; struct Node *next; }*/void ReversePrint(Node *head){ // This is a "method-only" submission. // You only need to complete this method. if(head != NULL) { ReversePrint(head->n..
-
Reverse a linked list해커랭크(HackerRank) 2018. 8. 19. 17:20
1. 문제 2. 알고리즘키워드 - 구현, 링크리스트 3. 코드 123456789101112131415161718192021222324252627/* Reverse a linked list and return pointer to the head The input list will have at least one element Node is defined as struct Node { int data; struct Node *next; }*/Node* Reverse(Node *head){ // Complete this method Node *tail, *node; tail = NULL; while (head != NULL) { // 다음 노드를 넣어 준다. node = head->next; // head->..
-
Compare two linked lists해커랭크(HackerRank) 2018. 8. 19. 17:19
1. 문제 2. 알고리즘키워드 - 구현, 링크 리스트 3. 코드 123456789101112131415161718192021/* Compare two linked lists A and B Return 1 if they are identical and 0 if they are not. Node is defined as struct Node { int data; struct Node *next; }*/int CompareLists(Node *headA, Node* headB){ // This is a "method-only" submission. // You only need to complete this method if (headA == NULL && headB == NULL) { return 1; } ..
-
Insert a node at a specific position in a linked list해커랭크(HackerRank) 2018. 8. 19. 17:18
1. 문제 2. 알고리즘키워드 - 구현, 자료구조, 링크리스트 3. 코드 123456789101112131415161718192021222324252627282930313233343536/* Insert Node at a given position in a linked list head can be NULL First element in the linked list is at position 0 Node is defined as struct Node { int data; struct Node *next; }*/Node* InsertNth(Node *head, int data, int position){ Node *newNode = new Node();//(Node*)malloc(sizeof(Node));..