본문 바로가기

Leetcode

(16)
Merge Two Sorted Lists / leetcode / c++ class Solution { public: ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) { ListNode* head = new ListNode(); ListNode* point = new ListNode(); // for head if (list1 or list2) { if (list1 and list2) { if (list1->val val) { head->next = list1; point->next = list1; list1 = list1->next; } else { head->next = list2; point->next = list2; list2 = list2->next; } } else if (list1) { return list1..
Remove Nth Node From End of List, LeetCode, c++/cpp/c 1. 첫 번째 코드 class Solution { public: ListNode* removeNthFromEnd(ListNode* head, int n) { int cnt = 1; ListNode* from = new ListNode(); from->next = head; ListNode remove = *head; while (remove.next) { remove = *remove.next; cnt++; } remove = *from; for (int i = 0; i next and n != cnt) tmp->next = tmp->next->next; else head = head->next; return head; } }; Colored by Color Scripter cs 2. 2. 완성한 코드 ..
leetcode Reverse Integer Solution without LongLong: #include class Solution { public: int reverse(int x) { if (x == 0) return 0; else { bool type = x = 0; i--) r.push_back(s[i]); point = s.size(); if (0
Add Two Numbers leetcode 2 FIRST: class Solution { public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode* l3 = new ListNode; ListNode* t[111]; t[0] = new ListNode; l3->next = t[0]; int add = 0, sum; for(int i = 0; l1 or l2 or add; i++) { sum = 0; t[i + 1] = new ListNode; if (l1) { sum += l1->val; l1 = l1->next; } if (l2) { sum += l2->val; l2 = l2->next; } t[i]->val = ((sum + add) % 10); if (sum + add >= 1..
[MySQL] 176. Second Highest Salary[LeetCode Medium] - 1 https://leetcode.com/problems/second-highest-salary/ Second Highest Salary - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 해석 1 2 3 Write an SQL query to report the second highest salary from the Employee table. If there is no second highest salary, the query should report null. ..
[MySQL] 175. Combine Two Tables [LeetCode Easy] https://leetcode.com/problems/combine-two-tables/ Question: Write an SQL query to report the first name, last name, city, and state of each person in the Person table. If the address of a personId is not present in the Address table, report null instead. cs Solution: There are two table, Person and Address. So we can see that we have to use two table at the same time. In this case, We need 'JOIN..
[MySQL] 3. 175. Combine Two Tables [LeetCode Easy] https://leetcode.com/problems/combine-two-tables/ 해석: Write an SQL query to report the first name, last name, city, and state of each person in the Person table. If the address of a personId is not present in the Address table, report null instead. cs firstName , lastName, city, state를 출력하라, 그러나 Address table에 personId가 없으면, null을 리턴하라는 내용입니다. Person table과 Address table이 나오며 Null이 나오니, 두 테이블을 합..
[LeetCode Medium] 3. Longest Substring Without Repeating Characters [C/C++] https://leetcode.com/problems/longest-substring-without-repeating-characters/ Longest Substring Without Repeating Characters - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 해석 Given a string s, find the length of the longest substring without repeating characters. String s에서 가장 긴..