![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
曾英俊
这个作者很懒,什么都没留下…
展开
-
剑指 Offer 42. 连续子数组的最大和
class Solution { private int max(int a, int b) { return a > b ? a : b; } public int maxSubArray(int[] nums) { int maxSum = nums[0]; int sum = 0; for (int tmp: nums) { sum += tmp; ma.原创 2021-04-22 17:38:06 · 57 阅读 · 0 评论 -
剑指 Offer 19. 正则表达式匹配
class Solution { private int max(int a, int b) { return a > b ? a : b; } public boolean isMatch(String s, String p) { int n = s.length(); int m = p.length(); int[][] dp = new int[n + 1][m + 1]; dp[0.原创 2021-04-22 17:30:30 · 75 阅读 · 0 评论 -
剑指 Offer 10- II. 青蛙跳台阶问题
class Solution { private int[] num = new int[105]; private final static int MOD = 1000000007; public int numWays(int n) { num[0] = 1; num[1] = 1; for (int i = 2; i <= n; i++) { num[i] = (num[i - 1].原创 2021-04-21 22:50:58 · 66 阅读 · 0 评论 -
剑指 Offer 10- I. 斐波那契数列
class Solution { private int[] FIB = new int[105]; private int MOD = 1000000007; public int fib(int n) { FIB[0] = 0; FIB[1] = 1; for (int i = 2; i <= n; i++) { FIB[i] = (FIB[i - 1] + FIB[i - 2]) % MOD;.原创 2021-04-21 22:46:04 · 46 阅读 · 0 评论 -
剑指 Offer 67. 把字符串转换成整数
class Solution { private final static long INT_MAX = 2147483647l; private final static long INT_MIN = -2147483648l; public int strToInt(String str) { long res = 0; long intStatus = 1; int status = 0; for (int.原创 2021-04-15 00:12:44 · 121 阅读 · 0 评论 -
剑指 Offer 59 - II. 队列的最大值
class MaxQueue { private Queue q; private Deque dq; public MaxQueue() { q = new LinkedList(); dq = new LinkedList(); } public int max_value() { return dq.isEmpty() ? -1 : (int)dq.getFirst(); } .原创 2021-04-14 23:52:18 · 79 阅读 · 0 评论 -
剑指 Offer 59 - I. 滑动窗口的最大值
class Solution { public int[] maxSlidingWindow(int[] nums, int k) { int n = nums.length; if (n == 0 || k == 0) { return new int[0]; } int[] res = new int[n - k + 1]; int cnt = 0; Deque dq = n.原创 2021-03-27 00:36:22 · 83 阅读 · 0 评论 -
剑指 Offer 58 - II. 左旋转字符串
class Solution { public String reverseLeftWords(String s, int n) { String res = s.substring(n) + s.substring(0, n); return res; } }原创 2021-03-26 00:04:05 · 48 阅读 · 0 评论 -
剑指 Offer 35. 复杂链表的复制
/* // Definition for a Node. class Node { int val; Node next; Node random; public Node(int val) { this.val = val; this.next = null; this.random = null; } } */ class Solution { public Node copyRandomList(Nod.原创 2021-03-26 00:00:25 · 80 阅读 · 0 评论 -
剑指 Offer 30. 包含 min 函数的栈
class MinStack { private Stack<Integer> var1; private Stack<Integer> var2; /** initialize your data structure here. */ public MinStack() { var1 = new Stack(); var2 = new Stack(); } public void pu.原创 2021-03-22 10:53:23 · 52 阅读 · 0 评论 -
剑指 Offer 24. 反转链表
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public ListNode reverseList(ListNode head) { if (head == null) { .原创 2021-03-21 23:54:16 · 59 阅读 · 0 评论 -
剑指 Offer 20. 表示数值的字符串
class Solution { public boolean isNumber(String s) { if (s == null || s.length() == 0) { return false; } int state = 0; for (int i = 0; i < s.length(); i++) { char now = s.charAt(i); .原创 2021-03-21 23:42:57 · 47 阅读 · 0 评论 -
剑指 Offer 09. 用两个栈实现队列
class CQueue { private Stack<Integer> var1; private Stack<Integer> var2; public CQueue() { var1 = new Stack(); var2 = new Stack(); } public void appendTail(int value) { var1.push(value); }.原创 2021-03-20 11:38:26 · 48 阅读 · 0 评论 -
剑指 Offer 06. 从尾到头打印链表
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public int[] reversePrint(ListNode head) { Stack<Integer> s = new St.原创 2021-03-20 10:29:22 · 42 阅读 · 0 评论 -
剑指 Offer 05. 替换空格
class Solution { public String replaceSpace(String s) { String res = ""; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == ' ') { res += ("%20"); } else { res += s.char.原创 2021-03-19 22:16:38 · 39 阅读 · 0 评论