Leetcode
Agiz
这个作者很懒,什么都没留下…
展开
-
leetcode 1402. 做菜顺序
一个厨师收集了他 n 道菜的满意程度 satisfaction ,这个厨师做出每道菜的时间都是 1 单位时间。一道菜的 「喜爱时间」系数定义为烹饪这道菜以及之前每道菜所花费的时间乘以这道菜的满意程度,也就是 time[i]*satisfaction[i] 。请你返回做完所有菜 「喜爱时间」总和的最大值为多少。你可以按 任意 顺序安排做菜的顺序,你也可以选择放弃做某些菜来获得更大的总和。 示例 1:输入:satisfaction = [-1,-8,0,5,-9]输出:14解释:去掉原创 2020-07-24 17:08:33 · 202 阅读 · 0 评论 -
leetcode 338. 比特位计数
给定一个非负整数 num。对于 0 ≤ i ≤ num 范围中的每个数字 i ,计算其二进制数中的 1 的数目并将它们作为数组返回。示例 1:输入: 2输出: [0,1,1]示例 2:输入: 5输出: [0,1,1,2,1,2]方法一:n&(n - 1)将n的二进制最后一个1变为0class Solution { public int[] countBits(int num) { int[] ans = new int[num + 1];原创 2020-07-24 16:05:52 · 125 阅读 · 0 评论 -
Design Linked List 设计链表
Design your implementation of the linked list. You can choose to use the singly linked list or the doubly linked list. A node in a singly linked list should have two attributes: val and next. val is t...原创 2019-03-24 17:57:56 · 121 阅读 · 0 评论 -
Triples with Bitwise AND Equal To Zero 三元组位与得0
Given an array of integers A, find the number of triples of indices (i, j, k) such that:0 <= i < A.length0 <= j < A.length0 <= k < A.lengthA[i] & A[j] & A[k] == 0, wher...原创 2019-04-04 21:00:08 · 320 阅读 · 0 评论 -
Minimum Falling Path Sum 最小路径dp
Given a square array of integers A, we want the minimum sum of a falling path through A.A falling path starts at any element in the first row, and chooses one element from each row. The next row's ...原创 2019-03-31 13:11:08 · 117 阅读 · 0 评论 -
Flatten a Multilevel Doubly Linked List 多级链表合并
You are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a separate doubly linked list. These child lists ma...原创 2019-03-23 20:50:45 · 104 阅读 · 0 评论 -
Stone Game 二维dp
Alex and Lee play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].The objective of the game is to en...原创 2019-03-30 13:48:49 · 140 阅读 · 0 评论 -
Split Linked List in Parts 将链表分段
Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list "parts".The length of each part should be as equal as possible: no two part...原创 2019-03-23 11:30:37 · 235 阅读 · 0 评论 -
Longest Palindromic Substring 最长回文子序列
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Exampl...原创 2019-03-26 13:42:02 · 105 阅读 · 0 评论 -
Counting Bits dp 位运算
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.题意:给出一个num,计算0到n之间的数的二进...原创 2019-03-29 21:35:15 · 95 阅读 · 0 评论 -
Reorder List 链表重新排序
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You may not modify the values in the list's nodes, only nodes itself may be changed.Example 1:Given 1->2-&...原创 2019-03-18 23:38:24 · 159 阅读 · 0 评论 -
Palindrome Linked List 链表是否对称
Given a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueFollow up:Could you do it in O(n) time and O...原创 2019-03-21 17:39:18 · 144 阅读 · 0 评论 -
Remove Duplicates from Sorted List II删除有序链表中所有相同元素
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.Example 1:Input: 1->2->3->3->4->4->5Output: 1->...原创 2019-03-13 11:38:39 · 106 阅读 · 0 评论 -
Partition List 链表按值分段
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of t...原创 2019-03-18 12:59:58 · 308 阅读 · 0 评论 -
Minimum Cost For Tickets 旅行最小票价
In a country popular for train travel, you have planned some train travelling one year in advance. The days of the year that you will travel is given as an array days. Each day is an integer from 1 ...原创 2019-03-31 21:26:12 · 320 阅读 · 0 评论 -
Palindromic Substrings 回文串的个数
Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist ...原创 2019-03-31 22:00:24 · 253 阅读 · 0 评论 -
Score After Flipping Matrix
We have a two dimensional matrix A where each value is 0 or 1.A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s.Af...原创 2019-04-24 23:52:49 · 128 阅读 · 0 评论 -
Partition Labels 分割字符串
A string S of lowercase 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 th...原创 2019-04-24 13:25:10 · 148 阅读 · 0 评论 -
Minimum Add to Make Parentheses Valid
Given a string S of ‘(’ and ‘)’ parentheses, we add the minimum number of parentheses ( ‘(’ or ‘)’, and in any positions ) so that the resulting parentheses string is valid.Formally, a parentheses st...原创 2019-04-22 23:40:48 · 143 阅读 · 0 评论 -
2 Keys Keyboard
Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:Copy All: You can copy all the characters present on the notepad (partial copy ...原创 2019-04-13 19:49:34 · 107 阅读 · 0 评论 -
Integer Break 数学/dp
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.Example 1:Input: 2Output: 1...原创 2019-04-13 18:15:45 · 172 阅读 · 0 评论 -
Best Time to Buy and Sell Stock系列
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock),...原创 2019-04-09 19:29:12 · 114 阅读 · 0 评论 -
Minimum ASCII Delete Sum for Two Strings 最长公共子序列变种2
Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal.Example 1:Input: s1 = "sea", s2 = "eat"Output: 231Explanation: Deleting "s" from "sea" adds the...原创 2019-04-03 11:45:11 · 117 阅读 · 0 评论 -
Delete Operation for Two Strings 最长公共子序列变种
Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character in either string.Example 1:Input: "sea...原创 2019-04-03 11:38:56 · 143 阅读 · 0 评论 -
House Robber 一维dp
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house...原创 2019-03-28 21:57:02 · 107 阅读 · 0 评论 -
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 ...原创 2019-03-28 10:38:47 · 132 阅读 · 0 评论 -
Arithmetic Slices 等差数列个数
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequence:...原创 2019-04-01 14:05:20 · 174 阅读 · 0 评论 -
Delete Columns to Make Sorted III 最长上升子序列变种
We are given an array A of N lowercase letter strings, all of the same length.Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices.For...原创 2019-04-06 21:12:17 · 148 阅读 · 0 评论 -
Odd Even Linked List 链表奇偶结点分开
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in p...原创 2019-03-21 17:10:42 · 241 阅读 · 0 评论 -
Remove Duplicates from Sorted List删除有序链表中的相同元素
Given a sorted linked list, delete all duplicates such that each element appear only once.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Output: 1->...原创 2019-03-13 11:08:53 · 119 阅读 · 0 评论 -
Linked List Components 找出连续的链表段
We are given head, the head node of a linked list containing unique integer values.We are also given the list G, a subset of the values in the linked list.Return the number of connected components...原创 2019-03-24 19:02:53 · 237 阅读 · 0 评论 -
Remove Nth Node From End of List删除链表倒数第n个结点
Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, th...原创 2019-03-09 16:59:53 · 93 阅读 · 0 评论 -
Merge k Sorted Lists k个链表合并
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3->4-...原创 2019-03-09 16:40:31 · 97 阅读 · 0 评论 -
Hamming Distance 位运算
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.Note:0 ≤ x, y < 23...原创 2019-03-09 15:22:42 · 171 阅读 · 0 评论 -
带环链表
Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail co...原创 2019-03-06 19:12:40 · 125 阅读 · 0 评论 -
Symmetric Tree判断二叉树是否对称
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But...原创 2019-02-25 22:25:50 · 101 阅读 · 0 评论 -
Climbing Stairs 递推 斐波那契
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positive...原创 2019-02-25 22:02:33 · 168 阅读 · 0 评论 -
Single Number 找出不同的数
Given a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without us...原创 2019-03-04 22:38:00 · 130 阅读 · 0 评论 -
Best Time to Buy and Sell Stock 贪心
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock),...原创 2019-03-04 22:19:42 · 74 阅读 · 0 评论 -
Maximum Depth of Binary Tree 二叉树高度
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A leaf is a node with no childre...原创 2019-03-04 22:04:14 · 75 阅读 · 0 评论