摘要: replace法,但是比较耗时 public String intToRoman(int num) { String rawStr = firstConvert(num); rawStr = rawStr.replace("DCCCC", "CM"); rawStr = rawStr.replace 阅读全文
posted @ 2023-02-24 11:04 jrjewljs 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 正经解法 把一个小值放在大值的左边,就是做减法,否则为加法. import java.util.*; class Solution { public int romanToInt(String s) { int sum = 0; int preNum = getValue(s.charAt(0)); 阅读全文
posted @ 2023-02-22 17:25 jrjewljs 阅读(26) 评论(0) 推荐(0) 编辑
摘要: 首先最好想的,肯定就是暴力解法,但是太慢了。 class Solution { public int maxArea(int[] height) { int max = 0; for (int i = 0; i < height.length; i++) { for (int j = i + 1; 阅读全文
posted @ 2023-02-22 17:02 jrjewljs 阅读(17) 评论(0) 推荐(0) 编辑
摘要: 从当前的状态s,输入一个字符,变成下一个状态s',这种类型叫做状态机,准确地说,这是确定有限状态机(deterministic finite automaton, DFA) class Solution { public int myAtoi(String str) { Automaton auto 阅读全文
posted @ 2023-02-22 16:48 jrjewljs 阅读(26) 评论(0) 推荐(0) 编辑
摘要: 快指针与慢指针 在环中,快指针走两步,慢指针走一步,快慢指针一定会相遇。需要注意的是,快慢指针相遇的地方,不一定是环的入口。 public static boolean isCircleByTwoPoint(ListNode head){ if (null == head || null == he 阅读全文
posted @ 2023-02-22 14:10 jrjewljs 阅读(26) 评论(0) 推荐(0) 编辑
摘要: pass 阅读全文
posted @ 2023-02-16 17:09 jrjewljs 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 错误解法 并不是说,正数溢出就会变成负数,正数溢出之后有可能依然是正数,以下是错误的思路 public int reverse(int x) { if (x > 0) { return reversePositive(x); } else { return -1 * reversePositive( 阅读全文
posted @ 2023-02-16 16:57 jrjewljs 阅读(17) 评论(0) 推荐(0) 编辑
摘要: public String convert(String s, int numRows) { if (s.isEmpty() || s == null || numRows >= s.length() || numRows == 1) { return s; } int n = s.length() 阅读全文
posted @ 2023-02-15 16:53 jrjewljs 阅读(73) 评论(0) 推荐(0) 编辑
摘要: 暴力解法 public String longestPalindrome(String s) { int max = 0; int start = 0; int n = s.length(); for (int i = 0; i < n; i++) { for (int j = i; j < n; 阅读全文
posted @ 2023-02-15 16:52 jrjewljs 阅读(15) 评论(0) 推荐(0) 编辑
摘要: public int KMPSearch(String s, String subStr) { int[] next = generateNext(subStr); int i = 0; // full string index int j = 0; // sub string index int 阅读全文
posted @ 2023-02-14 17:40 jrjewljs 阅读(16) 评论(0) 推荐(0) 编辑