Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 57c462c

Browse files
committedDec 27, 2020
add leetcode solution
1 parent 9c670a4 commit 57c462c

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed
 

‎README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
|647|[Palindromic Substrings](https://leetcode.com/problems/palindromic-substrings/) | |Medium|
7676
|643|[Maximum Average Subarray I](https://leetcode.com/problems/maximum-average-subarray-i/description/) | |Easy|
7777
|628|[Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers/) | |Easy|
78-
|627|[Swap Salary](https://leetcode.com/problems/swap-salary/) | [Mysql](./algorithm/swapSalary/Solution.java) | |Easy|
78+
|627|[Swap Salary](https://leetcode.com/problems/swap-salary/) | [Mysql](./algorithm/swapSalary/Solution.java) | |Medium|
79+
|626|[Exchange Seats](https://leetcode.com/problems/exchange-seats/) | [Mysql](./algorithm/swapSalary/Solution.java) | |Easy|
7980
|623|[Add One Row to Tree](https://leetcode.com/problems/add-one-row-to-tree/) | |Medium|
8081
|620|[Not Boring Movies](https://leetcode.com/problems/not-boring-movies/)| [Mysql](./algorithms/notBoringMovies/Solution.sql) |Easy|
8182
|617|[Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees/)| [Java](./algorithms/mergeTwoBinaryTrees/Solution.java)
@@ -193,6 +194,7 @@
193194
|268|[Missing Number](https://leetcode.com/problems/missing-number/)| |Medium|
194195
|264|[Ugly Number II](https://leetcode.com/problems/ugly-number-ii/)| |Medium|
195196
|263|[Ugly Number](https://leetcode.com/problems/ugly-number/)| |Easy|
197+
|262|[Trips and Users](https://leetcode.com/problems/trips-and-users/)| [Mysql](./algorithms/tripsAndUsers/Solution.sql) |Hard|
196198
|260|[Single Number III](https://leetcode.com/problems/single-number-iii/)| |Medium|
197199
|258|[Add Digits](https://leetcode.com/problems/add-digits/)| |Easy|
198200
|257|[Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths/)| |Easy|
@@ -233,7 +235,7 @@
233235
|208|[Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree/)| |Medium|
234236
|207|[Course Schedule](https://leetcode.com/problems/course-schedule/)| |Medium|
235237
|206|[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)| [java](./algorithms/reverseLinkedList/Solution.java), [js](./algorithms/reverseLinkedList/reverseLinkedList.js) |Easy|
236-
|205|[Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings/)| |Easy|
238+
|205|[Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings/)| [java](./algorithms/ismorphicStrings/Solution.java) |Easy|
237239
|204|[Count Primes](https://leetcode.com/problems/count-primes/)| |Easy|
238240
|203|[Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements/)| [js](./algorithms/removeLinkedListElements/removeLinkedListElements.js),[java](./algorithms/removeLinkedListElements/Solution.java) |Easy|
239241
|202|[Happy Number](https://leetcode.com/problems/happy-number/)| |Easy|

‎algorithms/exchangeSeats/Solution.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Write your MySQL query statement below
2+
-- 交换 Id 确实比较巧妙
3+
SELECT
4+
(CASE
5+
WHEN MOD(id, 2) != 0 AND counts != id THEN id + 1
6+
WHEN MOD(id, 2) != 0 AND counts = id THEN id
7+
ELSE id - 1
8+
END) AS id,
9+
student
10+
FROM
11+
seat,
12+
(SELECT
13+
COUNT(*) AS counts
14+
FROM
15+
seat) AS seat_counts
16+
ORDER BY id ASC;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public boolean isIsomorphic(String s, String t) {
3+
Map<Character, Character> s2t = new HashMap<Character, Character>();
4+
Map<Character, Character> t2s = new HashMap<Character, Character>();
5+
int len = s.length();
6+
for (int i = 0; i < len; ++i) {
7+
char x = s.charAt(i), y = t.charAt(i);
8+
if ((s2t.containsKey(x) && s2t.get(x) != y) || (t2s.containsKey(y) && t2s.get(y) != x)) {
9+
return false;
10+
}
11+
s2t.put(x, y);
12+
t2s.put(y, x);
13+
}
14+
return true;
15+
}
16+
}

‎algorithms/tripsAndUsers/Solution.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- # Write your MySQL query statement below
2+
SELECT T.request_at AS `Day`,
3+
ROUND(
4+
SUM(
5+
IF(T.STATUS = 'completed',0,1)
6+
)
7+
/
8+
COUNT(T.STATUS),
9+
2
10+
) AS `Cancellation Rate`
11+
FROM Trips AS T
12+
JOIN Users AS U1 ON (T.client_id = U1.users_id AND U1.banned ='No')
13+
JOIN Users AS U2 ON (T.driver_id = U2.users_id AND U2.banned ='No')
14+
WHERE T.request_at BETWEEN '2013-10-01' AND '2013-10-03'
15+
GROUP BY T.request_at

0 commit comments

Comments
 (0)
Please sign in to comment.