摘要:
class Solution { public List<List<Integer>> fourSum(int[] nums, int target) { List<List<Integer>> res = new ArrayList<>(); Arrays.sort(nums); for(int 阅读全文
摘要:
##O(n^3)解法 class Solution { public int sumOddLengthSubarrays(int[] arr) { int res = 0; int n = arr.length; for(int i=0;i<n;i++){ for(int j=i;j<n;j++){ 阅读全文
摘要:
##动态规划 class Solution { public int minimumOperations(String leaves) { int n = leaves.length(); int [][]state = new int[n][3]; char[] leaveArr = leaves 阅读全文
摘要:
今日快乐源泉:既然只能访问当前节点,那就只好出此下策了。杀不掉我,我就变成你,然后再干掉你,就等于杀死了自己。 面试题 02.03. 删除中间节点 实现一种算法,删除单向链表中间的某个节点(即不是第一个或最后一个节点),假定你只能访问该节点。 示例: 输入:单向链表a->b->c->d->e->f中 阅读全文
摘要:
class Solution { List<List<Integer>> res = new ArrayList<>(); List<Integer> list = new LinkedList<>(); public List<List<Integer>> combinationSum(int[] 阅读全文
摘要:
题目链接:https://leetcode-cn.com/problems/binary-tree-paths/ 前序遍历 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode 阅读全文
摘要:
我参加的机试是昨天晚上19:00到21:00,三道编程题目 由于考试期间在牛客网需要录屏所以没办法得到准确题目(华为允许使用本地IDE),我只能按照记忆描述 ##题目1 大概意思是:有n个人,每一个人都有一种礼物(礼物种类有两种,1是A类,2是B类),求三个人礼物数量(同种类)相加和最大,如果存在多 阅读全文
摘要:
题目链接:https://leetcode-cn.com/problems/repeated-substring-pattern/ 暴力法: class Solution { public boolean repeatedSubstringPattern(String s) { if(s.lengt 阅读全文
摘要:
题目链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/ ##题解:双指针 /** * Definition for singly-linked list. * public class ListNode { 阅读全文
摘要:
题目链接:https://leetcode-cn.com/problems/swap-nodes-in-pairs/ 注意这个交换不是这样的:1234-》2134-》2314-》2341 这道题一旦1和2交换后,这两项就固定了,严格意义来说是一对一对相交换而不是相邻 ##题解1 此题我将两个节点交换 阅读全文