Skip to content

Commit 6f9f6b5

Browse files
committed
2 parents 608334a + 0253a8c commit 6f9f6b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+732
-205
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 SDE603
3+
Copyright (c) 2018 RichCodersAndMe
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

MAINTENANCE_NOTES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- [其他问题](#其他问题)
1313

1414
## 本仓库的起源
15-
为避免误解,以下称[SDE603/LeetCode-Solution][lcs]**本仓库**, 被介绍的仓库称为**此仓库**
15+
为避免误解,以下称[RichCodersAndMe/LeetCode-Solution][lcs]**本仓库**, 被介绍的仓库称为**此仓库**
1616
### 来源1: [@Blankj][blankj][awsome-java-leetcode][ajl]
1717
**此仓库**[@Blankj][blankj]于2017年4月18日创建, 不定期更新优质**Java**代码和题解,颇受好评,至今已有star数**3521**颗(star数量以仓库原址为准)。截止**本仓库**建立为止, **此仓库**已累计拥有**63**题已AC的Java代码。
1818
### 来源2: [@Wang-YS][wys][leetcode][lc]
@@ -72,7 +72,7 @@ commit信息模板: ``feat: add the solution of `Two Sum`(001) with Java``
7272
[ajl]: https://github.com/Blankj/awesome-java-leetcode
7373
[wys]: https://github.com/Wang-YS
7474
[lc]: https://github.com/Wang-YS/leetcode
75-
[lcs]: https://github.com/SDE603/LeetCode-Solution
75+
[lcs]: https://github.com/RichCodersAndMe/LeetCode-Solution
7676
[old-lcs]: https://github.com/CodeAntStudio/LeetCode-Solution
7777
[wangxin]: https://github.com/relish-wang
7878
[Mukyu]: https://github.com/Mukyu

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
| [038][038-question] | [Count and Say][038-tips] | [][038-java] | | [][038-kotlin] |
4242
| [053][053-question] | [Maximum Subarray][053-tips] | [][053-java] | | [][053-kotlin] |
4343
| [058][058-question] | [Length of Last Word][058-tips] | [][058-java] | | [][058-kotlin] |
44-
| [066][066-question] | [Plus One][066-tips] | [][066-java] | | |
45-
| [067][067-question] | [Add Binary][067-tips] | [][067-java] | | |
46-
| [069][069-question] | [Sqrt(x)][069-tips] | [][069-java] | | |
47-
| [070][070-question] | [Climbing Stairs][070-tips] | [][070-java] | | |
48-
| [083][083-question] | [Remove Duplicates from Sorted List][083-tips] | [][083-java] | | |
44+
| [066][066-question] | [Plus One][066-tips] | [][066-java] | | [][066-kotlin] |
45+
| [067][067-question] | [Add Binary][067-tips] | [][067-java] | | [][067-kotlin] |
46+
| [069][069-question] | [Sqrt(x)][069-tips] | [][069-java] | | [][069-kotlin] |
47+
| [070][070-question] | [Climbing Stairs][070-tips] | [][070-java] | | [][070-kotlin] |
48+
| [083][083-question] | [Remove Duplicates from Sorted List][083-tips] | [][083-java] | | [][083-kotlin] |
4949
| [088][088-question] | [Merge Sorted Array][088-tips] | [][088-java] | | |
5050
| [100][100-question] | [Same Tree][100-tips] | [][100-java] | | |
5151
| [101][101-question] | [Symmetric Tree][101-tips] | [][101-java] | | |
@@ -69,10 +69,10 @@
6969
| [661][661-question] | [Image Smoother][661-tips] | [][661-java] | [][661-js] | |
7070
| [665][665-question] | [Non-decreasing Array][665-tips] | [][665-java] | [][665-js] | |
7171
| [669][669-question] | [Trim a Binary Search Tree][669-tips] | [][669-java] | [][669-js] | |
72-
| [671][671-question] | [Second Minimum Node In a Binary Tree][671-tips] | | [][671-js] | |
73-
| [674][674-question] | [Longest Continuous Increasing Subsequence][674-tips] | | [][674-js] | |
74-
| [680][680-question] | [Valid Palindrome II][680-tips] | | [][680-js] | |
75-
| [682][682-question] | [Baseball Game][682-tips] | | [][682-js] | |
72+
| [671][671-question] | [Second Minimum Node In a Binary Tree][671-tips] | [][671-java] | [][671-js] | |
73+
| [674][674-question] | [Longest Continuous Increasing Subsequence][674-tips] | [][674-java] | [][674-js] | |
74+
| [680][680-question] | [Valid Palindrome II][680-tips] | [][680-java] | [][680-js] | |
75+
| [682][682-question] | [Baseball Game][682-tips] | [][682-java] | [][682-js] | |
7676
| [686][686-question] | [Repeated String Match][686-tips] | | [][686-js] | |
7777
| [687][687-question] | [Longest Univalue Path][687-tips] | | [][687-js] | |
7878
| [693][693-question] | [Binary Number with Alternating Bits][693-tips] | | [][693-js] | |
@@ -465,6 +465,10 @@
465465
[661-java]: ./src/_661/Solution.java
466466
[665-java]: ./src/_665/Solution.java
467467
[669-java]: ./src/_669/Solution.java
468+
[671-java]: ./src/_671/Solution.java
469+
[674-java]: ./src/_674/Solution.java
470+
[680-java]: ./src/_680/Solution.java
471+
[682-java]: ./src/_682/Solution.java
468472
[728-java]: ./src/_728/Solution.java
469473
[771-java]: ./src/_771/Solution.java
470474
[804-java]: ./src/_804/Solution.java
@@ -484,4 +488,9 @@
484488
[038-kotlin]: ./src/_038/kotlin/Solution.kt
485489
[053-kotlin]: ./src/_053/kotlin/Solution.kt
486490
[058-kotlin]: ./src/_058/kotlin/Solution.kt
491+
[066-kotlin]: ./src/_066/kotlin/Solution.kt
492+
[067-kotlin]: ./src/_067/kotlin/Solution.kt
493+
[069-kotlin]: ./src/_069/kotlin/Solution.kt
494+
[070-kotlin]: ./src/_070/kotlin/Solution.kt
495+
[083-kotlin]: ./src/_083/kotlin/Solution.kt
487496
[771-kotlin]: ./src/_771/kotlin/Solution.kt

src/_066/kotlin/Solution.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package _066.kotlin
2+
3+
import java.util.*
4+
5+
/**
6+
* @author relish
7+
* @since 2018/04/19
8+
*/
9+
class Solution {
10+
fun plusOne(digits: IntArray): IntArray {
11+
var flag = 1
12+
val len = digits.size
13+
for (i in len - 1 downTo 0) {
14+
digits[i] += flag
15+
if (digits[i] >= 10) {
16+
digits[i] %= 10
17+
flag = 1
18+
continue
19+
}
20+
flag = 0
21+
break
22+
}
23+
if (flag == 1) {
24+
return IntArray(len+1,fun(index: Int):Int{
25+
if(index==0)return 1
26+
return digits[index-1]
27+
})
28+
}
29+
return digits
30+
}
31+
}
32+
33+
fun main(args: Array<String>) {
34+
println(Arrays.toString(Solution().plusOne(intArrayOf(9, 9, 9, 9))))
35+
}
36+
//val ret = IntArray(len + 1)
37+
//ret[0] = 1
38+
//for (i in digits.indices) {
39+
// ret[i + 1] = digits[i]
40+
//}
41+
//return ret

src/_067/kotlin/Solution.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package _067.kotlin
2+
3+
/**
4+
* @author relish
5+
* @since 2018/04/20
6+
*/
7+
class Solution {
8+
fun addBinary(a: String, b: String): String {
9+
val sb = StringBuilder()
10+
var flag = 0
11+
var i = a.length - 1
12+
var j = b.length - 1
13+
while (i >= 0 || j >= 0) {
14+
val ta = if (i < 0) 0 else a[i] - '0'
15+
val tb = if (j < 0) 0 else b[j] - '0'
16+
val t = ta + tb + flag
17+
flag = if (t > 1) 1 else 0
18+
sb.append(if (t > 1) t - 2 else t)
19+
i--
20+
j--
21+
}
22+
if (flag == 1) {
23+
sb.append('1')
24+
}
25+
return sb.reverse().toString()
26+
}
27+
}
28+
29+
fun main(args: Array<String>) {
30+
println(Solution().addBinary("1111", "1111"))
31+
}

src/_069/kotlin/Solution.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package _069.kotlin
2+
3+
/**
4+
* @author relish
5+
* @since 2018/04/21
6+
*/
7+
class Solution {
8+
fun mySqrt(x: Int): Int {
9+
var k = x.toLong()
10+
while (k * k > x)
11+
k = (k + x / k) / 2
12+
return k.toInt()
13+
}
14+
}
15+
16+
fun main(args: Array<String>) {
17+
println(Solution().mySqrt(2147395599))
18+
println(Solution().mySqrt(8))
19+
println(Solution().mySqrt(120))
20+
}

src/_070/kotlin/Solution.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package _070.kotlin
2+
3+
/**
4+
* @author relish
5+
* @since 2018/04/22
6+
*/
7+
class Solution {
8+
fun climbStairs(n: Int): Int {
9+
if (n == 1) return 1
10+
if (n == 2) return 2
11+
12+
var a = 1
13+
var b = 2
14+
var c: Int
15+
for (i in 2 until n) {
16+
c = b
17+
b += a
18+
a = c
19+
}
20+
return b
21+
}
22+
}
23+
24+
fun main(args: Array<String>) {
25+
println(Solution().climbStairs(3))
26+
}
27+

src/_083/kotlin/Solution.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package _083.kotlin
2+
3+
import structure.ListNode
4+
5+
/**
6+
* @author relish
7+
* @since 2018/04/23
8+
*/
9+
/**
10+
* Definition for singly-linked list.
11+
* class ListNode(var `val`: Int = 0) {
12+
* var next: ListNode? = null
13+
* }
14+
*/
15+
class Solution {
16+
fun deleteDuplicates(head: ListNode?): ListNode? {
17+
if (head == null) return head
18+
var cur = head
19+
while (cur!!.next != null) {
20+
if (cur.`val` == cur.next.`val`) {
21+
cur.next = cur.next.next
22+
} else {
23+
cur = cur.next
24+
}
25+
}
26+
return head
27+
}
28+
}
29+
30+
fun main(args: Array<String>) {
31+
val n = ListNode(1)
32+
n.next = ListNode(1)
33+
n.next.next = ListNode(2)
34+
n.next.next.next = ListNode(3)
35+
n.next.next.next.next = ListNode(3)
36+
var listNode = Solution().deleteDuplicates(n)
37+
while (listNode != null) {
38+
println(listNode.`val`)
39+
listNode = listNode.next
40+
}
41+
}

src/_671/Solution.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package _671;
2+
3+
import java.util.Stack;
4+
5+
/**
6+
* Definition for a binary tree node.
7+
* public class TreeNode {
8+
* int val;
9+
* TreeNode left;
10+
* TreeNode right;
11+
* TreeNode(int x) { val = x; }
12+
* }
13+
*/
14+
class Solution {
15+
public int findSecondMinimumValue(TreeNode root) {
16+
Stack<TreeNode> stack = new Stack<>();
17+
int min = root.val;
18+
int secMin = -1;
19+
stack.push(root);
20+
21+
while (!stack.empty()) {
22+
TreeNode node = stack.pop();
23+
24+
if (node.val > min) {
25+
if (node.val < secMin || secMin == -1) {
26+
secMin = node.val;
27+
}
28+
continue;
29+
}
30+
31+
if (node.left != null) {
32+
stack.push(node.right);
33+
stack.push(node.left);
34+
}
35+
}
36+
37+
return secMin;
38+
}
39+
40+
class TreeNode {
41+
int val;
42+
TreeNode left;
43+
TreeNode right;
44+
45+
TreeNode(int x) {
46+
val = x;
47+
}
48+
}
49+
}

src/_674/Solution.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package _674;
2+
3+
class Solution {
4+
public int findLengthOfLCIS(int[] nums) {
5+
if (nums.length == 0) {
6+
return 0;
7+
}
8+
int len = 1;
9+
int maxLen = 1;
10+
for (int i = 1; i < nums.length; i++) {
11+
if (nums[i] > nums[i-1]) {
12+
len++;
13+
if (len > maxLen) {
14+
maxLen = len;
15+
}
16+
} else {
17+
len = 1;
18+
}
19+
}
20+
return maxLen;
21+
}
22+
23+
public static void main(String[] args) {
24+
Solution solution = new Solution();
25+
System.out.println(solution.findLengthOfLCIS(new int[] {1, 3, 5, 4, 7}));
26+
System.out.println(solution.findLengthOfLCIS(new int[] {2, 2, 2, 2}));
27+
}
28+
}

src/_680/Solution.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package _680;
2+
3+
class Solution {
4+
public boolean validPalindrome(String s) {
5+
int l = 0;
6+
int r = s.length() - 1;
7+
while (l < r) {
8+
if (s.charAt(l) != s.charAt(r)) {
9+
return isPalindrome(s, l + 1, r) || isPalindrome(s, l, r - 1);
10+
}
11+
l++;
12+
r--;
13+
}
14+
return l >= r;
15+
}
16+
17+
private boolean isPalindrome(String s, int l, int r) {
18+
while (l < r) {
19+
if (s.charAt(l) != s.charAt(r)) {
20+
return false;
21+
}
22+
l++;
23+
r--;
24+
}
25+
return true;
26+
}
27+
28+
public static void main(String[] args) {
29+
Solution solution = new Solution();
30+
System.out.println(solution.validPalindrome("aba"));
31+
System.out.println(solution.validPalindrome("abca"));
32+
System.out.println(solution.validPalindrome("ececcec"));
33+
}
34+
}

src/_682/Solution.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package _682;
2+
3+
class Solution {
4+
public int calPoints(String[] ops) {
5+
int[] scores = new int[1000];
6+
int sum = 0;
7+
int i = 0;
8+
9+
for (String op : ops) {
10+
if (op.charAt(0) == 'C') {
11+
sum -= scores[i--];
12+
continue;
13+
}
14+
15+
i++;
16+
if (op.charAt(0) == '+') {
17+
scores[i] = scores[i-1] + scores[i-2];
18+
} else if (op.charAt(0) == 'D') {
19+
scores[i] = scores[i - 1] * 2;
20+
} else {
21+
scores[i] = Integer.valueOf(op);
22+
}
23+
sum += scores[i];
24+
}
25+
26+
return sum;
27+
}
28+
29+
public static void main(String[] args) {
30+
Solution solution = new Solution();
31+
System.out.println(solution.calPoints(new String[]{"5","-2","4","C","D","9","+","+"}));
32+
}
33+
}

0 commit comments

Comments
 (0)