- 博客(68)
- 收藏
- 关注
原创 leetcode 877.石子游戏
亚历克斯和李用几堆石子在做游戏。偶数堆石子排成一行,每堆都有正整数颗石子 piles[i] 。游戏以谁手中的石子最多来决出胜负。石子的总数是奇数,所以没有平局。亚历克斯和李轮流进行,亚历克斯先开始。 每回合,玩家从行的开始或结束处取走整堆石头。 这种情况一直持续到没有更多的石子堆为止,此时手中石子最多的玩家获胜。假设亚历克斯和李都发挥出最佳水平,当亚历克斯赢得比赛时返回 true ,当李赢得比赛时返回 false 。 示例:输入:[5,3,4,5]输出:true解释:亚历克斯
2020-07-24 23:56:59 711
原创 leetcode 1402. 做菜顺序
一个厨师收集了他 n 道菜的满意程度 satisfaction ,这个厨师做出每道菜的时间都是 1 单位时间。一道菜的 「喜爱时间」系数定义为烹饪这道菜以及之前每道菜所花费的时间乘以这道菜的满意程度,也就是 time[i]*satisfaction[i] 。请你返回做完所有菜 「喜爱时间」总和的最大值为多少。你可以按 任意 顺序安排做菜的顺序,你也可以选择放弃做某些菜来获得更大的总和。 示例 1:输入:satisfaction = [-1,-8,0,5,-9]输出:14解释:去掉
2020-07-24 17:08:33 190
原创 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 113
原创 import tensorflow包错误问题
我用的anaconda安装的python3.5的环境来学习tensorflow,导入各种包一切正常,然后学习网上用jupyter可以断点运行,我也想试一下,然后用anaconda navigator在之前创建的3.5版本的tensorflow环境中安装jupyter,在jupyter中导入tensorflow的包居然报错了,刚才在pycharm里还好好的,网上查相同的错误说是python版本不对引...
2019-05-21 21:34:29 872
原创 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 119
原创 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 137
原创 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 133
原创 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 98
原创 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 154
原创 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 100
原创 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 134
原创 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 309
原创 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 109
原创 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 132
原创 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 163
原创 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 244
原创 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 308
原创 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 104
原创 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 128
原创 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 83
原创 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 98
原创 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 126
原创 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 97
原创 Maximum Subarray 最大子段和
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanatio...
2019-03-24 21:50:41 104
原创 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 229
原创 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 113
原创 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 95
原创 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 226
原创 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 134
原创 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 230
原创 Add Two Numbers II 链表相加2
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return i...
2019-03-20 22:09:52 99
原创 Remove Linked List Elements 删除链表中等于某值的结点
Remove all elements from a linked list of integers that have value val.Example:Input: 1->2->6->3->4->5->6, val = 6Output: 1->2->3->4->5题意:如题。解法一:/** * Definiti...
2019-03-19 19:39:08 155
原创 Insertion Sort List 链表排序
Sort a linked list using insertion sort.A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.With each iteration one element ...
2019-03-19 19:19:36 79
原创 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 151
原创 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 301
原创 Reverse Nodes in k-Group 每隔k翻转链表
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the number of ...
2019-03-17 20:03:20 91
原创 Swap Nodes in Pairs交换链表的相邻结点
Given a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list's nodes, only nodes itself may be changed. Example:Given 1->2->3->4, y...
2019-03-16 14:44:38 124
原创 Intersection of Two Linked Lists找出两个链表相交的结点
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:![在这里插入图片描述](https://img-blog.csdnimg.cn/2019031601000677.pn...
2019-03-16 01:00:16 177
原创 Rotate List链表旋转
Given a linked list, rotate the list to the right by k places,where k is non-negative.Example 1:Input: 1-&gt;2-&gt;3-&gt;4-&gt;5-&gt;NULL, k = 2Output: 4-&gt;5-&gt;1-&gt;2-&
2019-03-14 14:38:54 131
原创 Reverse Linked List II逆置部分链表的一部分
Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5-&...
2019-03-14 13:37:24 153
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人