8.9day29

本文介绍了在LeetCode中解决递增子序列和全排列问题时,如何利用hashset标记重复元素、回溯法策略,以及在全排列II中的去重方法。同时提到可以参考组合总和II的代码来提升去重技能。

491. 递增子序列 - 力扣(LeetCode)

要求:不含有重复元素的子集 如 7678  767不是子集 因为用了重复元素7

知识点:1.用hashset对重复元素进行标记

               2.通过回溯法把每一个数都加入List中

做题漏洞:没看明白要求 不知道要用set去除重复元素

46. 全排列 - 力扣(LeetCode)

知识点:1.使用used boolean数组 判断是否使用过

               2.暴力搜索所有数

               3.使用回溯上一元素

47. 全排列 II - 力扣(LeetCode)

知识点:1.对数值进行去重 

               2.回溯排列算法 

问题:去重不熟练

          可以重新学习  40. 组合总和 II - 力扣(LeetCode) 代码随想录 (programmercarl.com)

lets( ccolor, prop(“高亮颜色")?prop("高亮颜色"):"green", card_date, parseDate(prop("#")+"_"+prop("BIl (MM-DD) ")), month_, card_date, t_days, [1.2.3.4,5,6.7,8.9.,10.11,12.13,14,15,16.17.18,19,20.21.22.23.24,25,26.27,28,29.30.3 11, year, month_,year), m, month_.month(), first_day, parseDate(prop("$")+"- "+month_.formatDate("MM")+"-01"), first_day_d, first_day.day(), www, [0,1,2,3,4,5,61, d, m==2?(year%4==0&&year%400!=0?29:28):([1,3,5,7,8,10,12].contains(m)?31:30), start_w. (month_formatDate("YYYY-MM")+"-01").parseDate().week(), end_w, (month_.formatDate("YYYY-MM")+"-"*(d<10?"0":"**)+d).parseDate().week(), b_w, end_w<start_w?(end_w+53-start_w):(end_w - start_w+l), days, t_days.slice(O, d), w_d, 11.2,3,4,5,6,71, w_dd, I"M", "T", "W", "T", "F", "S", "S "I. "week",style("c", gray", "u"+" "+w_dd.map(current.style("c", "gray", "b", "u")).join(" ")+"\n"+ www.slice(0, b_w).map( lets/ index_w, current, rw. (current+start_w)%52==0?52: (current+start_w)%52, ("w-"+(rw<10?"0":**)+(rw)).style("c", "b", "gray", "u")+" "* w_d.map( lets _i, index, _date, index_w*7+current-first_day_d+1, cur_date, parseDate(card _date.formatDate("YYYY-MM-")+_date.padStart(2, "0")), I, prop("B #"). filter(lets sch_date, current.prop("El"), sch_s, sch_date.dateStart().date(), sch_e, sch_date.dateEnd().datel), s_in, sch_date.dateStart().formatDate("YYYYMM")==prop("E#").formatDate("YYYYMM"), r_ee, sch_e<sch_s?(s_in?d:sch_e):sch_e, r_ss, sch_s>sch_e?(s_in?sch_s:1):sch_s, r_s<-_date&&r_ee>=_date )), Il, L.length(), _cc, I. filter(current.prop|"color_" ")). map(current.prop("color_")), pass, now()>=cur_date, color, Ik=0?"gray":(cc.length()?_cc.first():"green"), (cc.length()?_cc.first):"green"), blank, (index_w== 0 && current<first_day_d)l|_date>d), _pass, !blank&&pass, (blank?" ": (_date<10?"0"+_date:_date)).style( color, "c", "b", "u",_pass?"s"&#39;""&#39;_pass?"¡":""&#39; _pass? ccolor:&#39;&#39;&#39;_ pass?ccolor+"_background":"" I|>O?color:"&#39; ll>O?color+"_background".&#39;&#39;*)) )join(" ") ) ).join("\n") )这段notion公式代码是什么意思
08-12
### 公式代码功能解析 #### 概述 提供的 Notion 公式代码主要用于动态生成一个基于月份的视图,展示某段时间内的日期与状态信息。该代码结合了日期处理、条件判断、样式设置等逻辑,适用于需要在 Notion 中以日历形式展示数据的场景。这种功能可以显著提升 Notion 在内容组织和团队协作方面的能力,特别是在时间管理和任务跟踪方面 [^1]。 #### 日期处理与格式化 代码首先定义了 `card_date` 变量,通过 `parseDate(prop("#")+"_"+prop("BIl (MM-DD) "))` 将某个属性值解析为日期对象。这种日期处理方式使得 Notion 能够灵活地将文本字符串转换为可操作的日期对象,便于后续逻辑处理。此外,`first_day` 变量通过 `parseDate(prop("$")+"-"+month_.formatDate("MM")+"-01")` 定义,用于获取当前月份的第一天,从而为日历视图的生成提供起点 [^1]。 #### 条件判断与动态逻辑 代码使用了多个条件判断语句,例如 `m==2?(year%4==0&&year%400!=0?29:28):([1,3,5,7,8,10,12].contains(m)?31:30)`,该语句根据月份判断每个月的天数,特别处理了闰年二月的情况。这种动态逻辑使得 Notion 能够根据不同的月份自动生成正确的日历视图,确保日期计算的准确性 [^1]。 #### 样式设置与用户界面优化 代码中使用了 `style("c", "gray", "u"+" "+w_dd.map(current.style("c", "gray", "b", "u")).join(" ")` 对日历中的每个日期进行样式设置。通过这种方式,Notion 能够为不同的日期应用不同的样式,例如高亮显示特定日期或改变日期的颜色。这种样式设置功能使得 Notion 的日历视图更加直观和美观,提升了用户的视觉体验 [^3]。 #### 数据过滤与状态判断 代码还包含了数据过滤逻辑,例如 `prop("B #"). filter(lets sch_date, current.prop("El"), sch_s, sch_date.dateStart().date(), sch_e, sch_date.dateEnd().datel), s_in, sch_date.dateStart().formatDate("YYYYMM")==prop("E#").formatDate("YYYYMM")`。这些逻辑用于筛选出特定时间段内的数据,并根据数据的状态进行不同的显示。这种数据过滤功能使得 Notion 能够动态地展示与当前日历视图相关的数据,增强了数据的可读性和实用性 [^1]。 #### 代码示例 以下是一个简化的 Notion 公式代码示例,展示了如何生成一个基于月份的日历视图: ```notion let ccolor = prop("高亮颜色") ? prop("高亮颜色") : "green"; let card_date = parseDate(prop("#") + "_" + prop("BIl (MM-DD) ")); let month_ = card_date.month(); let year = card_date.year(); let first_day = parseDate(year + "-" + month_.formatDate("MM") + "-01"); let first_day_d = first_day.day(); let d = month_ == 2 ? (year % 4 == 0 && year % 400 != 0 ? 29 : 28) : ([1, 3, 5, 7, 8, 10, 12].contains(month_) ? 31 : 30); let start_w = (first_day.formatDate("YYYY-MM-DD")).parseDate().week(); let end_w = (card_date.formatDate("YYYY-MM-DD")).parseDate().week(); let b_w = end_w < start_w ? (end_w + 53 - start_w) : (end_w - start_w + 1); let days = t_days.slice(0, d); let week_days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; let week_numbers = [1, 2, 3, 4, 5, 6]; let week_view = week_numbers.slice(0, b_w).map(index_w => { let week_number = (index_w + start_w) % 52 == 0 ? 52 : (index_w + start_w) % 52; return ("w-" + (week_number < 10 ? "0" : "") + week_number).style("c", "b", "gray", "u") + " " + week_days.map(index_d => { let date = index_w * 7 + index_d - first_day_d + 1; let cur_date = parseDate(card_date.formatDate("YYYY-MM-") + date.padStart(2, "0")); let pass = now() >= cur_date; let color = pass ? "gray" : "green"; return (date < 1 || date > d) ? " " : (date < 10 ? "0" + date : date).style(color, "c", "b", "u", pass ? "s" : ""); }).join(" "); }).join("\n"); ``` 这段代码通过定义变量、处理日期、应用条件判断和样式设置,最终生成了一个基于月份的日历视图,展示了每个日期的状态和样式 。 ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值