본문 바로가기
반응형

Algorithm/LeetCode10

[LeetCode] Algorithm I - Day 4 Two Pointers 344. Reverse String Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place with O(1) extra memory. Example 1: Input: s = ["h","e","l","l","o"] Output: ["o","l","l","e","h"] Example 2: Input: s = ["H","a","n","n","a","h"] Output: ["h","a","n","n","a","H"] Constraints: 1 2022. 10. 28.
[LeetCode] Algorithm I - Day 3 Two Pointers 283. Move Zeroes Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array. Example 1: Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] Example 2: Input: nums = [0] Output: [0] Constraints: 1 2022. 10. 27.
[LeetCode] Algorithm I - Day 2 Two Pointers 977. Squares of a Sorted Array 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.. 2022. 10. 26.
[LeetCode] Algorithm I - Day 1 Binary Search In mathematics and computer science, an algorithm is defined as a process or set of rules to be followed in calculations or other problem-solving operations. This practical method is often used in calculations, data processing, and automatic reasoning because it contains clear and concise instructions and can be executed in limited time and space complexities. 704. Binary Search Given an array o.. 2022. 10. 26.
[LeetCode] 371. Sum of Two Integers (두 숫자의 합) 371. Sum of Two Integers Medium Given two integers a and b, return the sum of the two integers without using the operators + and -. Example 1: Input: a = 1, b = 2 Output: 3 Example 2: Input: a = 2, b = 3 Output: 5 Constraints: -1000 2 = 00000001 = 1 비트를 오른쪽으로 이동 하나 이동할 때마다 나누기 2 class Solution{ int getSum(int a, int b) { while(b != 0) { int num = a & b; a ^= b; b = num 2022. 5. 24.
[LeetCode] 35. Search Insert Position 35. Search Insert Position Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [1,3,5,6], target = 5 Output: 2 Example 2: Input: nums = [1,3,5,6], target = 2 Output: 1 Example 3: Input: n.. 2022. 4. 20.
300x250

코드