Skip to content

Commit cbff710

Browse files
committed
6/6
1 parent 290379a commit cbff710

File tree

2 files changed

+57
-19
lines changed

2 files changed

+57
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Easy Leetcode 1287
2+
tags: Array
3+
4+
方法1:
5+
题目不难最直观的解法 计算出现的次数
6+
方法2
7+
非常巧妙的方法更巧妙的计算次数
8+
方法3
9+
采用二分法
10+
11+
12+
13+
```
14+
15+
/*
16+
方法1
17+
*/
18+
class Solution {
19+
public int findSpecialInteger(int[] arr) {
20+
if(arr.length == 1) {
21+
return arr[0];
22+
}
23+
int len = 1;
24+
for (int i = 0; i < arr.length; i++) {
25+
if(arr[i] == arr[i+1]) {
26+
len++;
27+
if(len > arr.length/4) {
28+
return arr[i];
29+
}
30+
}else{
31+
len = 1;
32+
}
33+
}
34+
return 1;
35+
}
36+
}
37+
38+
/*
39+
方法2
40+
*/
41+
public int findSpecialInteger(int[] arr) {
42+
int n = arr.length, t = n / 4;
43+
44+
for (int i = 0; i < n - t; i++) {
45+
if (arr[i] == arr[i + t]) {
46+
return arr[i];
47+
}
48+
}
49+
return -1;
50+
}

README.md

+7-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1+
12
# leetcode-journey
2-
my journey to leetcode solutions
33

4-
### ff
54

6-
**README.md**: 所有所做过的题目
5+
here I write down every problem I solved with my initial thought and second thoughts after reviewing many brilliant solutions proposed in the discussion section.
76

7+
172/1469 Solved
8+
Easy 167
9+
Medium 4
10+
Hard 1
811

9-
| Squence | Problem | Level | Language | Tags | Note |
10-
|:-------:|:--------------|:------:|:---------:|:----:|:-------------:|
11-
|0|[Two Sum.java](https://github.com/u4989190/LintCode/blob/master/Java/0-Two%20Sum.java)|Easy|Java|[ss]||
12-
|1|[Reverse Integer.java](https://github.com/u4989190/LintCode/blob/master/Java/1-Reverse%20Integer.java)|Easy|Java|[]||
13-
|2|[Palindrome Number.java](https://github.com/u4989190/LintCode/blob/master/Java/2-Palindrome%20Number.java)|Easy|Java|[ss]||
14-
|3|[Roman to Integer.java](https://github.com/u4989190/LintCode/blob/master/Java/0-Two%20Sum.java)|Easy|Java|[ss]||
15-
|4|[Loggest Common Prefix.java](https://github.com/u4989190/LintCode/blob/master/Java/0-Two%20Sum.java)|Easy|Java|[ss]||
16-
|5|[Valid Parentheses.java](https://github.com/u4989190/LintCode/blob/master/Java/5-Valid%20Parentheses.java)|Easy|Java|[String]||
17-
|6|[Merge Two Sorted Lists.java](https://github.com/u4989190/LintCode/blob/master/Java/5-Valid%20Parentheses.java)|Easy|Java|[Linked List]||
18-
|7|[Implement sStringtrStr().java](https://github.com/u4989190/LintCode/blob/master/Java/5-Valid%20Parentheses.java)|Easy|Java|[]||
19-
|8|[Count and Say.java](https://github.com/u4989190/LintCode/blob/master/Java/5-Valid%20Parentheses.java)|Easy|Java|[String]||
20-
|9|[Length of Last Word.java](https://github.com/u4989190/LintCode/blob/master/Java/5-Valid%20Parentheses.java)|Easy|Java|[String]||
21-
|10|[Valid Palindrome.java](https://github.com/u4989190/LintCode/blob/master/Java/5-Valid%20Parentheses.java)|Easy|Java|[String]||
22-
|12|[Reverse Vowels of a String.java](https://github.com/u4989190/LintCode/blob/master/Java/5-Valid%20Parentheses.java)|Easy|Java|[String]||
23-
|13|[Ransom Note.java](https://github.com/u4989190/LintCode/blob/master/Java/5-Valid%20Parentheses.java)|Easy|Java|[String]||
24-
|14|[First Unique Character in a String.java](https://github.com/u4989190/LintCode/blob/master/Java/5-Valid%20Parentheses.java)|Easy|Java|[String]||
12+
[my leetcode account page](https://leetcode.com/u4989190/)

0 commit comments

Comments
 (0)