본문 바로가기

ALGORITHM

(38)
LeetCode 21. Merge Two Sorted Lists https://leetcode.com/problems/merge-two-sorted-lists /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */ import java.util.ArrayList; class Solution { public ListNode mergeTwoLists(ListNode list1, ListNode list2) { ListN..
LeetCode 234 Palindrome Linked List https://leetcode.com/problems/palindrome-linked-list /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */ class Solution { public boolean isPalindrome(ListNode head) { ListNode node = head; Stack stack = new Stack(); Arr..
릿코드 1.TWO SUM https://leetcode.com/problems/two-sum/ class Solution { public int[] twoSum(int[] nums, int target) { int[] result = new int[2]; for(int i = 0; i < nums.length; i++) { for(int j = 0; j < nums.length; j++) { if(i != j) { if(nums[i] + nums[j] == target) { System.out.println("nums[i] = " + nums[i]); System.out.println("nums[j] = " + nums[j]); result[0] = i; result[1] = j; return result; } } } } ret..
383. Ransom Note https://leetcode.com/problems/ransom-note/description/?envType=study-plan-v2&envId=top-interview-150 Ransom Note - LeetCode Can you solve this real interview question? Ransom Note - Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise. Each letter in magazine can only be used once in ranso leetcode.com 1.아이..
102. Binary Tree Level Order Traversal https://leetcode.com/problems/binary-tree-level-order-traversal/description/?envType=study-plan-v2&envId=top-interview-150 Binary Tree Level Order Traversal - LeetCode Can you solve this real interview question? Binary Tree Level Order Traversal - Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level). Example 1: [https:..
169. Majority Element https://leetcode.com/problems/majority-element/description/?envType=study-plan-v2&envId=top-interview-150 Majority Element - LeetCode Can you solve this real interview question? Majority Element - Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists leetcode.com..
88. Merge Sorted Array https://leetcode.com/problems/merge-sorted-array/description/?envType=study-plan-v2&envId=top-interview-150 Merge Sorted Array - LeetCode Can you solve this real interview question? Merge Sorted Array - You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 an lee..
637. Average of Levels in Binary Tree https://leetcode.com/problems/average-of-levels-in-binary-tree/description/?envType=study-plan-v2&envId=top-interview-150 Average of Levels in Binary Tree - LeetCode Can you solve this real interview question? Average of Levels in Binary Tree - Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10-5 of the actual answer wi..