Algorithm
题目描述
输入一个链表,输出该链表中倒数第k个结点。
输入
{1,2,3,4,5},1
返回值
{5}
代码
import java.util.*;
/*
* public class ListNode {
* int val;
* ListNode next = null;
* public ListNode(int val) {
* this.val = val;
* }
* }
*/
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param pHead ListNode类
* @param k int整型
* @return ListNode类
*/
public ListNode FindKthToTail (ListNode pHead, int k) {
if(pHead == null){
return null;
}
// write code here
ListNode p1 = pHead;
ListNode p2 = pHead;
for(int i = 0; i < k; i++){
if(p1 == null){
return null;
}
p1 = p1.next;
}
while(p1 != null){
p1 = p1.next;
p2 = p2.next;
}
return p2;
}
}
Review
https://medium.com/insider/i-tried-planking-for-5-minutes-every-day-for-a-month-heres-what-happened-4e5051b42b58
这篇文章讲了作者自己挑战坚持一个月每天5分钟的平板支撑,以及自己每个阶段的经历,也用事实证明了有些事情并没有捷径,要想做得好就得努力去做,如果能持之以恒,哪怕没有做得特别完美,回过头也能发现自己从中也获得了巨大的收获。
Tips
1、全屏的Dialog若使用默认主题,在Android7以上系统(是否该条件下出现还有待验证,只是大致猜测),通过setContentView设置的内容无法全屏,可以通过随便设置一个其他的主题来解决
2、SDK开发过程中,若需要使用到某些主题,尽量不要直接使用,例如
new Dialog(context, android.R.style.Theme_Light)
最好改为通过getResources().getIdentifier()方法去获取资源id,防止因为找不到资源而出现闪退问题
context.getResources().getIdentifier(id, type, pkgName)
3、根据时间戳校验两个时间是否为同一天的方法:
方案一:
(timestamp + 时区 * 3600) / (24 * 60 * 60)
该公式可以计算出时间戳对应的天数,两个时间戳由该公式可以计算出两个值,若相同即为同一天
该方案需要先定好时区
方案二:
利用SimpleDateFormat将时间戳转换为具体日期,在判断是否为同一天
Share
https://juejin.cn/post/6907620425837051917