본문 바로가기
728x90
반응형

Algorithm32

[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_SQL] 1484. Group Sold Products By The Date - Oracle & MySQL Table Activities: +-------------+---------+ | Column Name | Type | +-------------+---------+ | sell_date | date | | product | varchar | +-------------+---------+ There is no primary key for this table, it may contain duplicates. Each row of this table contains the product name and the date it was sold in a market. Write an SQL query to find for each date the number of different products sold and.. 2022. 8. 13.
[LeetCode_SQL] 1667. Fix Names in a Table - Oracle & MySQL Table: Users +----------------+---------+ | Column Name | Type | +----------------+---------+ | user_id | int | | name | varchar | +----------------+---------+ user_id is the primary key for this table. This table contains the ID and the name of the user. The name consists of only lowercase and uppercase characters. Write an SQL query to fix the names so that only the first character is uppercas.. 2022. 8. 13.
[LeetCode_SQL] 196. Delete Duplicate Emails - Oracle & MySQL 196. Delete Duplicate Emails Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | email | varchar | +-------------+---------+ id is the primary key column for this table. Each row of this table contains an email. The emails will not contain uppercase letters. Write an SQL query to delete all the duplicate emails, keeping only one unique email wi.. 2022. 8. 13.
[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.
[Java] 숫자 뒤집기 알고리즘 public int reverse(int x) { // x = -1234 int rev = 0; while(x!=0) { rev = rev*10 + x%10; x/=10; } return rev; // -4321 } 1. -1234를 끝에서부터 한 개씩 자른다 2. 잘려진 숫자를 맨 앞에 차례대로 위치시킨다 끝에 숫자를 가져오려면? x 를10으로 나눈 나머지를 가져오면 된다. -1234를 10으로 나누면 몫이 -123이고 나머지가 -4가 된다. 즉, 나머지를 가져온다는 건 마지막 자리 숫자를 가져오겠다는 뜻 rev에 10을 곱하고 내가 가져온 마지막 숫자를 더해서 맨 앞으로 가져올 수 있다. public int reverse2(int x) { // x = -1234 int rev = 0; while(x>.. 2022. 5. 15.
728x90
반응형