본문 바로가기
  • Jetpack 알아보기

LeetCode/Easy18

[Java] LeetCode 1518 : Water Bottles LeetCode # 1518 Example 1: Input: numBottles = 9, numExchange = 3 Output: 13 Explanation: You can exchange 3 empty bottles to get 1 full water bottle. Number of water bottles you can drink: 9 + 3 + 1 = 13. Constraints: 1 2021. 4. 17.
[Java] LeetCode 290 : Word Pattern LeetCode # 290 Example 1: Input: pattern = "abba", s = "dog cat cat dog" Output: true Note: 1 2021. 4. 17.
[Java] LeetCode 914 : X of a Kind in a Deck of Cards LeetCode # 914 Example 1: Input: deck = [1,2,3,4,4,3,2,1] Output: true Explanation: Possible partition [1,1],[2,2],[3,3],[4,4]. Note: 1 2021. 4. 17.
[Java] LeetCode 1486 : XOR Operation in an Array LeetCode # 1486 Given an integer n and an integer start. Define an array nums where nums[i] = start + 2*i (0-indexed) and n == nums.length. Return the bitwise XOR of all elements of nums. Example 1: Input: n = 5, start = 0 Output: 8 Explanation: Array nums is equal to [0, 2, 4, 6, 8] where (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8. Where "^" corresponds to bitwise XOR operator. Note: 1 2021. 4. 17.
[Java] LeetCode 977 : Squares of a Sorted Array LeetCode # 977 Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Example 1: Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, it becomes [0,1,9,16,100]. Example 2: Input: nums = [-7,-3,2,3,11] Output: [4,9,9,49,121] Constraints: 1 2021. 3. 30.
[Java] LeetCode 1295 : Find Numbers with Even Number of Digits LeetCode # 1295 Given an array nums of integers, return how many of them contain an even number of digits. Example 1: Input: nums = [12,345,2,6,7896] Output: 2 Explanation: 12 contains 2 digits (even number of digits). 345 contains 3 digits (odd number of digits). 2 contains 1 digit (odd number of digits). 6 contains 1 digit (odd number of digits). 7896 contains 4 digits (even number of digits)... 2021. 3. 30.
[Java] LeetCode 485 : Max Consecutive Ones LeetCode # 485 Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3. Note: The input array will only contain 0 and 1. The length of input array is a positive integer and will not exceed 10,000 Solution #1 (1ms.. 2021. 3. 30.
[JAVA] LeetCode Explore - May Week 1 : First Bad Version Week 1 : First Bad Version You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad. Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes a.. 2020. 5. 3.