
Leetcode每日随机2021/4/28
发布日期:2021-05-07 13:50:01
浏览次数:20
分类:原创文章
本文共 1792 字,大约阅读时间需要 5 分钟。
题
思
leetcode93
普通DFS。
leetcode1551
这是在逗我吗?这是中等题?这也太傻比了
leetcode1154
傻卵,考常识?
代码
class Solution { private List<List<String>> res = new ArrayList<List<String>>(); private Stack<String> stack = new Stack<String>(); public List<String> restoreIpAddresses(String s) { dfs(stack, s, 0); List<String> list = new ArrayList<String>(); for (List<String> ipList : res) { list.add(ipList.stream().collect(Collectors.joining("."))); } return list; } private void dfs(Stack<String> stack, String s, int idx) { if (stack.size() == 4) { if (idx == s.length()) { res.add(new ArrayList<String>(stack)); } return; } for (int i = 1; i < 4; i++) { if (idx + i > s.length()) { break; } String temp = s.substring(idx, idx + i); if (temp.length() > 1 && temp.startsWith("0")) { break; } if (Integer.valueOf(temp) < 256) { stack.push(temp); dfs(stack, s, idx + i); stack.pop(); } } }}
leetcode1551
class Solution { public int minOperations(int n) { int sum = 0; for (int i = 1; i < n; i += 2) { sum += n - i; } return sum; }}
leetcode1154
class Solution { public int dayOfYear(String date) { int[] count = new int[12]; count[0] = 31; count[1] = 28; count[2] = 31; count[3] = 30; count[4] = 31; count[5] = 30; count[6] = 31; count[7] = 31; count[8] = 30; count[9] = 31; count[10] = 30; count[11] = 31; String[] dates = date.split("-"); int year = Integer.valueOf(dates[0]); int month = Integer.valueOf(dates[1]); int day = Integer.valueOf(dates[2]); if (year % 4 == 0) { count[1] = 29; } if (year == 1900) { count[0] = 28; } int days = 0; for (int i = 0; i < month; i++) { if (i == month - 1) { days += day; } else { days += count[i]; } } return days; }}
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2025年03月26日 05时41分54秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
仿小米商城(下)
2019-03-04
C#成神之路<10> C#代码中制定决策
2019-03-04
C#成神之路<11> C#循环重复语句
2019-03-04
C#成神之路<17> C#使用磁盘数据文件(1)
2019-03-04
C#成魔之路<2>Windows 应用程序高级控件(2)
2019-03-04
textarea文本框根据输入内容多少自适应高度
2019-03-04
【30】kotlin 闭包
2019-03-04
【46】kotlin 集合框架
2019-03-04
【47】kotlin IO操作
2019-03-04
【55】Kotlin android Anko 神兵利器2
2019-03-04
git忽略规则以及.gitignore文件不生效解决办法
2019-03-04
文件md5怎么会变化
2019-03-04
tablayout 滑动监听
2019-03-04
ViewModel LiveData 使用初体验
2019-03-04
Error connecting to the service protoco
2019-03-04
windows 用户获取管理员权限
2019-03-04
Flutter 加载本地图片
2019-03-04
android带气泡的第三方选项卡
2019-03-04
好玩的editText
2019-03-04