Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jianJizz/JUC
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
  • Loading branch information
HadoopJ committed Aug 11, 2021
2 parents 3287d54 + 26f1061 commit 00bce34
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 60 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,5 @@
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.29</version>
</dependency>

</dependencies>
</project>
75 changes: 51 additions & 24 deletions src/main/java/com/usc/Test.java
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");
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/usc/leetcode/DigitCounts.java
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;
}
}
30 changes: 0 additions & 30 deletions src/main/java/com/usc/leetcode/FindContentChildern.java
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.

0 comments on commit 00bce34

Please sign in to comment.