摘要:
题目链接 在代码中需要注意的有: 本题给出的二进制数字是字符串形式,不可以转化成 int 型,因为可能溢出; 两个「加数」的字符串长度可能不同; 在最后,如果进位 carry 不为 0,那么最后需要计算进位; 向结果字符串 res 拼接的顺序是向后拼接,返回时需要把 res 反转 。 代码中的巧妙之 阅读全文
posted @ 2022-02-02 23:49
蹇爱黄
阅读(32)
评论(0)
推荐(0)
摘要:
力扣题目链接 遇到代替乘除或者优化乘除,首先考虑位运算 这道题需要注意Integer.MIN_VALUE 直接用减法来替代会超出时间限制 class Solution { public int divide(int a, int b) { if (b == 0) return 0; if (a == 阅读全文
posted @ 2022-02-02 23:27
蹇爱黄
阅读(50)
评论(0)
推荐(0)
摘要:
力扣题目链接 希望面试给我这道题 肯定不是利用String类中的replaceAll方法 class Solution { public String replaceSpace(String s) { return s.replaceAll(" ", "%20"); } } 方法一:字符数组 由于每 阅读全文
posted @ 2022-02-02 21:15
蹇爱黄
阅读(30)
评论(0)
推荐(0)
摘要:
题目链接 1.普通链表的定义: class Node{ int val; Node next; public Node(int val){ this.val = val; this.next = null; } 2.本题的复杂链表节点定义: class Node{ int val; Node nex 阅读全文
posted @ 2022-02-02 20:35
蹇爱黄
阅读(117)
评论(0)
推荐(0)
摘要:
题目链接 迭代 class Solution { public ListNode reverseList(ListNode head) { ListNode pre = null,cur = head,next = null; while(cur!=null){ //将cur.next存起来 nex 阅读全文
posted @ 2022-02-02 14:51
蹇爱黄
阅读(29)
评论(0)
推荐(0)
摘要:
题目链接 #1.for循环 class Solution { public int[] reversePrint(ListNode head) { ListNode temp = head; int n = 0; while(temp!=null){ temp = temp.next; n++; } 阅读全文
posted @ 2022-02-02 14:31
蹇爱黄
阅读(32)
评论(0)
推荐(0)
摘要:
力扣题目链接 class MinStack { //声明两个栈 A为数据栈,B为辅助栈 Stack<Integer> A,B; public MinStack() { //初始化栈 A = new Stack<>(); B = new Stack<>(); } public void push(in 阅读全文
posted @ 2022-02-02 12:43
蹇爱黄
阅读(30)
评论(0)
推荐(0)
摘要:
力扣题目链接 class CQueue { //全局声明两个栈 LinkedList<Integer> A,B; public CQueue() { //new两个栈 A = new LinkedList<Integer>(); B = new LinkedList<Integer>(); } pu 阅读全文
posted @ 2022-02-02 11:28
蹇爱黄
阅读(54)
评论(0)
推荐(0)