
算法
AliceWanderAI
北邮自动化学院,研究方向:图像处理,机器学习
展开
-
[Google Code Jam 2017] Round 2 problem A
problem description: You are the public relations manager for a chocolate manufacturer. Unfortunately, the company’s image has suffered because customers think the owner is cheap and miserly. You hope原创 2017-06-01 09:55:21 · 1438 阅读 · 0 评论 -
Code Jam to I/O for Women 2016【上】
这次code jam一共四大题。 下面分别详细展示A+B两道题的解题思路及Python代码。Problem A. Cody’s Jams 题目: ProblemCody, the owner of the legendary Cody’s Jams store, is planning a huge jam sale. To make things simple, he has decided原创 2017-05-23 16:36:53 · 1108 阅读 · 0 评论 -
Improve Path within 100 days
Operating system Coding language: C++ Algorithms Sorting Data structures Mathematics Graphs Recursion System Design Linux CudaLeetcode: 5*100 day (1*easy+3*medium+1*hard)100天的学习提升计划,每半个月至少进行一次面试实战。待续。。。...原创 2020-10-14 20:58:13 · 224 阅读 · 0 评论 -
[leetcode: Python]31.Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible orde原创 2017-05-23 16:11:19 · 893 阅读 · 0 评论 -
[leetcode: Python]24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may no原创 2017-05-19 15:37:25 · 1602 阅读 · 0 评论 -
[leetcode: Python]22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())", "(原创 2017-05-19 08:58:31 · 1277 阅读 · 0 评论 -
[leetcode: Python]19. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list be原创 2017-05-19 08:28:30 · 583 阅读 · 0 评论 -
[leetcode: Python]18.4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution set mu原创 2017-05-19 08:18:55 · 1068 阅读 · 0 评论 -
[leetcode: Python]6. ZigZag Conversion
The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I GY原创 2017-05-18 17:33:20 · 728 阅读 · 0 评论 -
[leetcode: Python]17. Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"O原创 2017-05-18 17:14:51 · 1896 阅读 · 0 评论 -
[leetcode: Python]16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly原创 2017-05-18 16:39:26 · 532 阅读 · 0 评论 -
[leetcode: Python]15.3Sum
题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain d原创 2017-05-18 16:25:10 · 467 阅读 · 0 评论 -
[leetcode: Python]12. Integer to Roman
题目: Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999. 题意: 把数字转换成罗马数字数字与罗马数字相互表示的原则: 方法一:119msclass Solution(object): def intToRoman(原创 2017-05-18 11:24:09 · 1463 阅读 · 0 评论 -
[leetcode: Python]11. Container With Most Water
title: Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find原创 2017-05-18 11:05:17 · 398 阅读 · 0 评论 -
[leetcode: Python]8.String to Integer
题目: Implement atoi to convert a string to an integer. 实现atoi函数 Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possi原创 2017-05-18 10:47:07 · 485 阅读 · 0 评论 -
[leetcode: Python]3. Longest Substring Without Repeating Characters
Title: Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", wit原创 2017-05-17 17:54:54 · 703 阅读 · 0 评论 -
[leetcode: Python]5.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:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Example:Inp原创 2017-05-17 10:32:45 · 1969 阅读 · 0 评论 -
[leetcode:python] 2.Add Two Numbers
题目描述: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and re原创 2017-05-10 11:36:07 · 654 阅读 · 0 评论 -
[leetcode: Python]572. Subtree of Another Tree
Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node’原创 2017-05-19 16:32:45 · 2753 阅读 · 0 评论 -
[leetcode: Python]566. Reshape the Matrix
In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’re given a matrix represented by a two-dimensio原创 2017-05-19 16:28:21 · 2485 阅读 · 0 评论 -
[leetcode: Python]563. Binary Tree Tilt
Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtree nod原创 2017-05-19 16:26:12 · 1319 阅读 · 1 评论 -
[leetcode: Python]561. Array Partition I
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possibl原创 2017-05-19 16:20:44 · 2354 阅读 · 0 评论 -
[leetcode: Python]557. Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contest"Output原创 2017-05-19 16:17:34 · 2258 阅读 · 0 评论 -
[leetcode: Python]551. Student Attendance Record I
You are given a string representing an attendance record for a student. The record only contains the following three characters:‘A’ : Absent. ‘L’ : Late. ‘P’ : Present. A student could be rewarded i原创 2017-05-19 16:15:05 · 843 阅读 · 0 评论 -
[leetcode: Python]543. Diameter of Binary Tree
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may no原创 2017-05-19 16:11:56 · 1995 阅读 · 0 评论 -
[leetcode: Python]29. Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.方法一:72ms 解题思路:不许用乘、除和求余实现两数的相除。那就只能用加和减了。正常思路是被除数一个一个的减除数,直到剩下的数比除数小为止,就得到了结果。这样是无法ac的,因为时原创 2017-05-19 16:07:07 · 2448 阅读 · 0 评论 -
[leetcode: Python]541. Reverse String II
Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them.原创 2017-05-18 18:12:37 · 1411 阅读 · 0 评论 -
[leetcode: Python]530. Minimum Absolute Difference in BST
Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example:Input: 1 \ 3 / 2Output:1Explanation:The minimum abs原创 2017-05-18 18:10:59 · 1168 阅读 · 0 评论 -
[leetcode: Python]520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters in this word原创 2017-05-18 18:05:42 · 992 阅读 · 0 评论 -
[leetcode: Python]507. Perfect Number
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.Now, given an integer n, write a function that returns true when it is a perfect n原创 2017-05-18 18:03:06 · 985 阅读 · 0 评论 -
[leetcode: Python]504. Base 7
Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"Note: The input will be in range of [-1e7, 1e7].实现七进制方法一:68msclass Solution(原创 2017-05-18 17:57:29 · 994 阅读 · 0 评论 -
[leetcode: Python]501. Find Mode in Binary Search Tree
Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.Assume a BST is defined as follows:The left subtree of a node contains onl原创 2017-05-18 17:53:59 · 1617 阅读 · 0 评论 -
[leetcode: Python]500.Keyboard Row
Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below.American keyboard Example 1:Input: ["Hello", "Alaska", "原创 2017-05-18 17:49:35 · 2071 阅读 · 0 评论 -
[leetcode: Python]492.Construct the Rectangle
For a web developer, it is very important to know how to design a web page’s size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L原创 2017-05-18 17:46:44 · 638 阅读 · 0 评论 -
[leetcode: Python]485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive 1s.原创 2017-05-18 17:43:03 · 1556 阅读 · 0 评论 -
[leetcode: Python]476. Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note: The given integer is guaranteed to fit within the range of a 32-b原创 2017-05-17 10:28:57 · 1442 阅读 · 0 评论 -
[leetcode: Python]475.Heaters
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses.Now, you are given positions of houses and heaters on a horizontal line,原创 2017-05-16 18:30:33 · 1060 阅读 · 0 评论 -
[leetcode: Python]463. Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely s原创 2017-05-16 18:26:53 · 1314 阅读 · 0 评论 -
[leetcode: Python]461. 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 < 231.Examp原创 2017-05-16 18:24:08 · 1170 阅读 · 0 评论 -
[leetcode: Python]459. Repeated Substring Pattern
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase Englis原创 2017-05-16 18:19:51 · 729 阅读 · 0 评论