Weikoi

导航

2020年2月22日 #

Leetcode-010-正则表达式匹配

摘要: 第二道Hard,插眼待完成。 阅读全文

posted @ 2020-02-22 20:29 Weikoi 阅读(73) 评论(0) 推荐(0) 编辑

Leetcode-009-回文数

摘要: 本题正常人思路都是用字符串处理。 这里注意一下Java中字符串是如何翻转的: class Solution { public boolean isPalindrome(int x) { String original = String.valueOf(x); return new StringBui 阅读全文

posted @ 2020-02-22 20:27 Weikoi 阅读(147) 评论(0) 推荐(0) 编辑

Leetcode-008-字符串转换整数

摘要: 本题没有技巧,主要是考查对各种corner case的处理, 留坑待补。 阅读全文

posted @ 2020-02-22 20:15 Weikoi 阅读(91) 评论(0) 推荐(0) 编辑

Leetcode-007-整数反转

摘要: 本题为基础题,注意两个点即可,其一为整数的上下限如何表示,其二是注意 Java 和 Python 的负数整除机制是不同的,Java -3/2 是 -1,而 Python -3 // 2 是 -2. class Solution { public int reverse(int x) { long r 阅读全文

posted @ 2020-02-22 15:53 Weikoi 阅读(170) 评论(0) 推荐(0) 编辑

Leetcode-006-Z字形变换

摘要: 本题解决思路是有限状态机FSM,构建排列时有两种状态,要么向上,要么向下,状态间如何切换呢?向上且处于第一行那就该掉头向下了,向下且处于最后一行那就改掉头向上了。思路就是这样。 class Solution { public String convert(String s, int numRows) 阅读全文

posted @ 2020-02-22 14:35 Weikoi 阅读(163) 评论(0) 推荐(0) 编辑

2020年2月21日 #

Leetcode-005-最长回文子串

摘要: 动态规划问题,用数组保存所有子串的回文状态,用 l 表示左游标,r 表示右游标,那么dp[l][r] 中的值即代表 l 到 r 这个长度的子串是否回文。 状态有两种判断条件,一种是 如果 l == r + 1 即子串长度为2, 那么只要这两个字符相等就是回文; 另外一种则是不但要求左端和右端字符相等 阅读全文

posted @ 2020-02-21 20:36 Weikoi 阅读(175) 评论(0) 推荐(0) 编辑

2020年2月20日 #

Leetcode-004-寻找两个有序数组的中位数

摘要: LC第一道Hard题目,插眼待完成。 阅读全文

posted @ 2020-02-20 23:22 Weikoi 阅读(112) 评论(0) 推荐(0) 编辑

Leetcode-003-无重复字符最长子串长度

摘要: 动态规划初级题,或者理解为滑动窗口。 class Solution { public int lengthOfLongestSubstring(String s) { Set<Character> demo = new HashSet<>(); int l=0,r=0,result=0; while 阅读全文

posted @ 2020-02-20 18:43 Weikoi 阅读(152) 评论(0) 推荐(0) 编辑

Leetcode-002-两数相加

摘要: 本题主要是考查对链表的操作。 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ cl 阅读全文

posted @ 2020-02-20 16:07 Weikoi 阅读(97) 评论(0) 推荐(0) 编辑

Leetcode-001-两数之和

摘要: 本题思路是用一个key-value数据结构去保存已经遍历到的数字。 public int[] twoSum(int[] nums, int target) { HashMap<Integer, Integer> hm = new HashMap<>(); for(int i =0; i<nums.l 阅读全文

posted @ 2020-02-20 14:31 Weikoi 阅读(108) 评论(0) 推荐(0) 编辑