![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
刷题
鸡蛋豆腐仙子
从本科开始讨厌了单片机 晶体管 编程 c++5-6年后,发现技术就是我的真爱,再重新选择一次,我还是会选择当程序员。我现在觉得自己什么都不会,可是还是相信会变成别人仰望的大神。
展开
-
AutocompleteSystem
Note:MANY DETAILS ARE MISSED:If less than 3, return as many as it. So it could be NPE when queue.poll().getKey()Use alphabetical order if times are same. So in the queu need to compare value first then compare string.Logically it needs to set chi转载 2021-08-11 23:21:37 · 76 阅读 · 0 评论 -
2021-06-20微软面试
package msinterview;public class CoinTransition {static int count = 0;public static void main(String[] args) {int[] coins = new int[] {1, 1, -1}; System.out.print(maxTransition(coins));}// 1是正面 -1是花static int maxTransition(int[] coins) { for (i原创 2021-06-20 12:36:02 · 107 阅读 · 0 评论 -
【刷题】leetcode 355. Design Twitter
public class Twitter { Map<Integer, Set<Integer>> fans = new HashMap<>(); Map<Integer, LinkedList<Tweet>> tweets = new HashMap<>(); int cnt = 0; public void postTweet(int userId, int tweetId) { i原创 2020-10-08 20:43:42 · 168 阅读 · 0 评论 -
【刷题】leetcode 113 path sum II
Example:Given the below binary tree and sum = 22, 5 / \4 8/ / 11 13 4/ \ / 7 2 5 1Return:[[5,4,11,2],[5,8,4,5]]/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; *原创 2020-10-08 15:12:53 · 79 阅读 · 0 评论 -
【刷题】leetcode 621 task schedule
Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task原创 2020-10-08 15:07:51 · 70 阅读 · 0 评论 -
【刷题】leetcode 763 partition labels
A string S of lowercase English letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.Example 1:Input: S = “ab原创 2020-10-08 15:02:44 · 92 阅读 · 0 评论 -
【刷题】Leetcode 394 decode string
用栈public class Solution { public String decodeString(String s) { String res = ""; Stack<Integer> countStack = new Stack<>(); Stack<String> resStack = new Stack<>(); int idx = 0; while (id原创 2020-10-08 14:59:04 · 62 阅读 · 0 评论 -
[刷题]连续整数
15=1+2+3+4+515=4+5+615=7+81.如果输入n是奇数,那连续整数可以表示为:n = (n-1)/2 + (n+1)/22.如果输入n是偶数,分两种情况:情况1:n一直除以2,如果最终结果是奇数(最终不是1),那n可以是连续奇数组成情况2:n一直除以2,结果一直是偶数,那无法形成连续的奇数,即该数是2的n次方...原创 2020-08-03 15:18:51 · 302 阅读 · 0 评论 -
刷题:(0,0)到(i,j)最大值
题目:2 31 2 31 0 2最大值:8DP算法public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int row = sc.nextInt(); int column = sc.nextInt(); int[][] dpMat = new int[row][column]原创 2020-07-31 18:00:57 · 192 阅读 · 0 评论 -
【刷题】Leetcode 171. Excel Sheet Column Number
有一段时间没有刷题了,因为我已经拿到**菊厂**的offer啦! 回头看写的这些博客,都是对做过的的题的总结,代码规范,时间复杂度,注释等写的还可以更好一些。 我知道自己的总结和格式都*不够*到位和漂亮,没有特别认真的去书写,都是做完题草草的留下来了而已。 所以,今后还是会更多的总结,包括这一年左右国内大厂的面经,分享给可能和我一样拧巴一样努力奋进想要铁杵成针的童鞋。 今天写这道题,是因为这是道面试原题哦!A -> 1B -> 2C -> 3…Z...原创 2020-05-26 15:51:57 · 102 阅读 · 0 评论 -
【刷题】Leetcode 146. LRU Cache
class LRUCache { HashMap<Integer, Node> map; int capacity; int count; Node head; Node tail; public LRUCache(int capacity) { map = new HashMap<Integer, Node>...原创 2020-04-11 21:04:37 · 124 阅读 · 0 评论 -
【刷题】Leetcode 300. Longest Increasing Subsequence
3 10 1 8 5 6 9 4 dp[]: 1 2 1 2 2 3 4 2public class Solution { public int lengthOfLIS(int[] nums) { if (nums.length == 0) { return 0; } int[] dp =...原创 2020-03-24 19:55:54 · 63 阅读 · 0 评论 -
【转花花】并查集
这里插入图片描述原创 2020-02-10 12:51:33 · 68 阅读 · 0 评论 -
[转自花花]fenwick tree
原创 2020-02-10 12:42:44 · 118 阅读 · 0 评论 -
93. Restore IP Addresses
Example:Input: “25525511135”Output: [“255.255.11.135”, “255.255.111.35”]class Solution { public List<String> restoreIpAddresses(String s) { List<String> list = new ArrayList();...原创 2019-12-25 15:23:17 · 48 阅读 · 0 评论 -
19. Remove Nth Node From End of List
/**Definition for singly-linked list.public class ListNode {int val;ListNode next;ListNode(int x) { val = x; }}*/class Solution {public ListNode removeNthFromEnd(ListNode head,...原创 2019-12-25 15:22:33 · 44 阅读 · 0 评论 -
【刷题】Leetcode 347. Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Output: [1]class Solution { ...原创 2019-12-18 19:16:49 · 95 阅读 · 0 评论 -
【刷题】Leetcode 746. Min Cost Climbing Stairs
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of t...原创 2019-12-09 15:55:11 · 54 阅读 · 0 评论 -
【刷题】Leetcode 494. Target Sum
Example 1:Input: nums is [1, 1, 1, 1, 1], S is 3.Output: 5Explanation:-1+1+1+1+1 = 3+1-1+1+1+1 = 3+1+1-1+1+1 = 3+1+1+1-1+1 = 3+1+1+1+1-1 = 3There are 5 ways to assign symbols to make the sum ...原创 2019-12-08 18:51:08 · 44 阅读 · 0 评论 -
【刷题】Leetcode 459. Repeated Substring Pattern
Example 1:Input: “abab”Output: TrueExplanation: It’s the substring “ab” twice.Example 2:Input: “aba”Output: False暴力法:public boolean repeatedSubstringPattern(String str) { int l = str.length()...原创 2019-12-06 16:04:18 · 118 阅读 · 0 评论 -
【刷题】Leetcode 862. Shortest Subarray with Sum at Least K
暴力解class Solution { public int shortestSubarray(int[] A, int K) { int[] P = new int[A.length + 1]; for(int i = 0; i < A.length; i++){ P[i + 1] = P[i] + A[i]; ...原创 2019-12-05 19:53:04 · 57 阅读 · 0 评论 -
【刷题】Leetcode 212. Word Search II
Example:Input:board = [[‘o’,‘a’,‘a’,‘n’],[‘e’,‘t’,‘a’,‘e’],[‘i’,‘h’,‘k’,‘r’],[‘i’,‘f’,‘l’,‘v’]]words = [“oath”,“pea”,“eat”,“rain”]Output: [“eat”,“oath”]避免有相同前缀的词重复查找比如“aaaaaax”, “aaaaaay” 所以...原创 2019-11-25 23:24:25 · 90 阅读 · 0 评论 -
【刷题】Leetcode 208. Implement Trie (Prefix Tree)
class TreeNode { char val; TreeNode[] next; boolean isEnd; public TreeNode(){ this.next = new TreeNode[26]; }}class Trie { public TreeNode root; /** Initialize ...原创 2019-11-25 19:23:22 · 79 阅读 · 0 评论 -
【刷题】Leetcode 341. Flatten Nested List Iterator
Example 1:Input: [[1,1],2,[1,1]]Output: [1,1,2,1,1]Explanation: By calling next repeatedly until hasNext returns false,the order of elements returned by next should be: [1,1,2,1,1].Example 2:Inp...原创 2019-11-25 09:50:15 · 133 阅读 · 0 评论 -
【刷题】Leetcode 236. Lowest Common Ancestor of a Binary Tree
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { Tr...原创 2019-11-24 23:06:40 · 75 阅读 · 0 评论 -
【刷题】Leetcode 10. Regular Expression Matching
‘.’ Matches any single character.‘*’ Matches zero or more of the preceding element.Example 1:Input:s = “aa”p = “a”Output: falseExplanation: “a” does not match the entire string “aa”.Example 2:...原创 2019-11-24 22:00:57 · 50 阅读 · 0 评论 -
【刷题】Leetcode 207. Course Schedule
There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair:...原创 2019-11-20 16:15:45 · 59 阅读 · 0 评论 -
【刷题】Leetcode 91. Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:‘A’ -> 1‘B’ -> 2…‘Z’ -> 26Given a non-empty string containing only digits, determine the tot...原创 2019-11-19 14:15:08 · 80 阅读 · 0 评论 -
【刷题】Leetcode 148. Sort List
Example 1:Input: 4->2->1->3Output: 1->2->3->4/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { va...原创 2019-11-19 12:55:05 · 52 阅读 · 0 评论 -
【刷题】Leetcode 96. Unique Binary Search Trees
Example:Input: 3Output: 5Explanation:Given n = 3, there are a total of 5 unique BST’s:1 3 3 2 1\ / / / \ 3 2 1 1 3 2/ / ...原创 2019-11-18 18:45:32 · 60 阅读 · 0 评论 -
【刷题】Leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal
For example, giveninorder = [9,3,15,20,7]postorder = [9,15,7,20,3]Return the following binary tree:3/ 9 20/ 15 7/** * Definition for a binary tree node. * public class TreeNode { * ...原创 2019-11-18 16:21:31 · 72 阅读 · 0 评论 -
【刷题】Leetcode 572. Subtree of Another Tree
Example 1:Given tree s 3/ \4 5/ 1 2Given tree t:4/ 1 2这里return啊,if啊的顺序很重要,要不得就错了/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode...原创 2019-11-18 16:15:06 · 54 阅读 · 0 评论 -
【刷题】Leetcode 50. Pow(x, n)
这两道easy题都写崩溃了。。。。Implement pow(x, n), which calculates x raised to the power n (xn).Example 1:Input: 2.00000, 10Output: 1024.00000用class Solution { public double myPow(double x, int n) { ...原创 2019-11-18 16:10:54 · 65 阅读 · 0 评论 -
【刷题】Leetcode 3. Longest Substring Without Repeating Characters
Example 1:Input: “abcabcbb”Output: 3Explanation: The answer is “abc”, with the length of 3.Example 2:Input: “bbbbb”Output: 1Explanation: The answer is “b”, with the length of 1.Example 3:Inpu...原创 2019-11-13 18:53:59 · 112 阅读 · 0 评论 -
【刷题】Leetcode 2. Add Two Numbers
**2. Add Two Number**class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { int jinwei = 0; ListNode head = new ListNode(0); ListNode p = head;...原创 2019-11-12 19:21:29 · 131 阅读 · 0 评论 -
【刷题】Leetcode 1. 2Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same e...原创 2019-11-11 13:06:26 · 67 阅读 · 0 评论 -
【刷题】Leetcode 200. Number of Islands
Example 1:Input:11110110101100000000Output: 1Example 2:Input:11000110000010000011Output: 3class Solution { public int numIslands(char[][] grid) { int count = 0; for(i...原创 2019-11-04 22:20:40 · 67 阅读 · 0 评论 -
【刷题】Leetcode 22. Generate Parentheses
For example, given n = 3, a solution set is:[“((()))”,“(()())”,“(())()”,“()(())”,“()()()”]这道题cc上有,很老了。class Solution { public List<String> generateParenthesis(int n) { List&...原创 2019-11-03 11:25:54 · 60 阅读 · 0 评论 -
【刷题】Leetcode559. Maximum Depth of N-ary Tree
DFS:/*// Definition for a Node.class Node { public int val; public List<Node> children; public Node() {} public Node(int _val,List<Node> _children) { val = _va...原创 2019-11-02 19:41:08 · 116 阅读 · 0 评论 -
【刷题】Leetcode 131. Palindrome Partitioning
Example:Input: “aab”Output:[[“aa”,“b”],[“a”,“a”,“b”]]搜索顺序a a ba abaa baabclass Solution { public List<List<String>> partition(String s) { List<List<String>...原创 2019-10-30 21:08:18 · 76 阅读 · 0 评论