-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:jianJizz/JUC
# Conflicts: # pom.xml
- Loading branch information
Showing
5 changed files
with
75 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,61 @@ | ||
package com.usc; | ||
|
||
class Test { | ||
public int firstBadVersion(int n) { | ||
int l = 1, r = n; | ||
while (l <= r) { | ||
int mid = l + r >> 1; | ||
// 1, 2, 3, 4, 5 | ||
// 0 0 0 1 1 | ||
boolean isBadMid = isBadVersion(mid); | ||
if (mid -1 >= l && isBadMid && isBadVersion(mid-1) == false){ | ||
return mid; | ||
class Solution { | ||
public int romanToInt(String s) { | ||
int result = 0; | ||
char numC; | ||
for(int index = s.length() - 1 ; index != -1 ; index -- ){ | ||
numC = s.charAt(index); | ||
if(numC == 'I'){ | ||
result += 1; | ||
} | ||
|
||
// 版本错误 | ||
if (isBadMid) { | ||
r = mid; | ||
}else{ | ||
l = mid; | ||
if(numC == 'V'){ | ||
result += 5; | ||
if(index != 0 && s.charAt(index - 1) == 'I'){ | ||
result --; | ||
index --; | ||
} | ||
} | ||
if(numC == 'X'){ | ||
result += 10; | ||
if(index != 0 && s.charAt(index - 1) == 'I'){ | ||
result --; | ||
index --; | ||
} | ||
} | ||
if(numC == 'L'){ | ||
result += 50; | ||
if(index != 0 && s.charAt(index - 1) == 'X'){ | ||
result -= 10; | ||
index --; | ||
} | ||
} | ||
if(numC == 'C'){ | ||
result += 100; | ||
if(index != 0 && s.charAt(index - 1) == 'X'){ | ||
result -= 10; | ||
index --; | ||
} | ||
} | ||
if(numC == 'D'){ | ||
result += 500; | ||
if(index != 0 && s.charAt(index - 1) == 'C'){ | ||
result -= 100; | ||
index --; | ||
} | ||
} | ||
if(numC == 'M'){ | ||
result += 1000; | ||
if(index != 0 && s.charAt(index - 1) == 'C'){ | ||
result -= 100; | ||
index --; | ||
} | ||
} | ||
} | ||
|
||
return -1; | ||
return result; | ||
} | ||
|
||
public boolean isBadVersion(int n) { | ||
if (n == 3) return true; | ||
return false; | ||
} | ||
public static void main(String[] args) { | ||
|
||
new Test().firstBadVersion(3); | ||
new Solution().romanToInt("IV"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.usc.leetcode; | ||
|
||
/** | ||
* 统计数字 | ||
*/ | ||
public class DigitCounts { | ||
public static void main(String[] args) { | ||
new DigitCounts().digitCounts(1, 12); | ||
} | ||
|
||
public int digitCounts(int k, int n) { | ||
int ans = 0; | ||
for(int i=0; i<=n; i++){ | ||
int j = i; | ||
while(j > 0){ | ||
if (j % 10 == k) ans++; | ||
j /= 10; | ||
} | ||
} | ||
|
||
|
||
return ans; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +0,0 @@ | ||
package com.usc.leetcode; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* @author jianjianduan | ||
* @date 2020/8/31 11:30 下午 | ||
*/ | ||
public class FindContentChildern { | ||
public static void main(String[] args) { | ||
findContentChildren(new int[]{10, 9, 8, 7}, new int[]{5, 6, 7, 8}); | ||
} | ||
public static int findContentChildren(int[] g, int[] s) { | ||
Arrays.sort(g); | ||
Arrays.sort(s); | ||
int ans = 0; | ||
int k = 0; | ||
for(int i=0; i<g.length; i++){ | ||
for(int j=0; j<s.length; j++){ | ||
if (s[j] >= g[i]) { | ||
ans++; | ||
k++; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
return ans; | ||
} | ||
} | ||
Empty file.