본문 바로가기
반응형

Algorithm32

[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.
[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.
[LeetCode] 3. Longest Substring Without Repeating Characters Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: s = "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Notice that the ans.. 2022. 4. 18.
[LeetCode] 58. Length of Last Word 58. Length of Last Word Given a string s consisting of some words separated by some number of spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only. Example 1: Input: s = "Hello World" Output: 5 Explanation: The last word is "World" with length 5. Example 2: Input: s = " fly me to the moon " Output: 4 Explanation: The last.. 2022. 4. 17.
300x250

코드