diff --git a/pom.xml b/pom.xml index 9a832bd..584c394 100644 --- a/pom.xml +++ b/pom.xml @@ -68,11 +68,5 @@ RELEASE compile - - com.alibaba - fastjson - 1.2.29 - - \ No newline at end of file diff --git a/src/main/java/com/usc/Test.java b/src/main/java/com/usc/Test.java index 4a11463..5fef7a4 100644 --- a/src/main/java/com/usc/Test.java +++ b/src/main/java/com/usc/Test.java @@ -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"); } } \ No newline at end of file diff --git a/src/main/java/com/usc/leetcode/DigitCounts.java b/src/main/java/com/usc/leetcode/DigitCounts.java new file mode 100644 index 0000000..58cb4fe --- /dev/null +++ b/src/main/java/com/usc/leetcode/DigitCounts.java @@ -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; + } +} diff --git a/src/main/java/com/usc/leetcode/FindContentChildern.java b/src/main/java/com/usc/leetcode/FindContentChildern.java index 6e4a731..e69de29 100644 --- a/src/main/java/com/usc/leetcode/FindContentChildern.java +++ b/src/main/java/com/usc/leetcode/FindContentChildern.java @@ -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[i]) { - ans++; - k++; - } - break; - } - } - - return ans; - } -} diff --git a/src/main/java/com/usc/leetcode/RotateRight.java b/src/main/java/com/usc/leetcode/RotateRight.java new file mode 100644 index 0000000..e69de29