算法课作业
Tonylamam
菜,还要继续努力
展开
-
leetcode week2
Determine whether an integer is a palindrome. Do this without extra space.问题描述:输入一个整数,判断其是否回文,即3223为回文,3224不是如此类推。要求不能使用额外空间。解题思路:首先要定义一下回文,按照题目的意思,整数之中,负数我们假定不为回文,然后小于10大于0的一位整数为回文。对于整数原创 2017-03-05 02:03:59 · 246 阅读 · 0 评论 -
leetcode week18
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1]原创 2017-06-21 14:08:01 · 251 阅读 · 0 评论 -
leetcode week17
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2017-06-20 17:05:49 · 269 阅读 · 0 评论 -
leetcode week16
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c原创 2017-06-20 15:18:50 · 252 阅读 · 0 评论 -
leetcode week15
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.问题描述:罗马数字转成数字的问题解题思路:罗马数字分一下几种1~9: {"I", "II", "III", "IV", "V", "VI", "VII"原创 2017-06-20 14:52:18 · 264 阅读 · 0 评论 -
leetcode week14
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.问题描述:问题比较简单,就是两个排好序的链表,要要把他们合并起来变成一个链表,并且也是排好序的。解题思路:解题原创 2017-06-02 17:43:38 · 205 阅读 · 0 评论 -
leetcode week9
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原创 2017-04-25 23:06:11 · 199 阅读 · 0 评论 -
leetcode week11
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the ta原创 2017-05-08 12:43:15 · 204 阅读 · 0 评论 -
leetcode week 10
Given a string containing just the characters '(', ')','{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all valid b原创 2017-05-08 12:06:08 · 181 阅读 · 0 评论 -
leetcode week12
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.原创 2017-05-15 13:35:05 · 266 阅读 · 0 评论 -
leetcode week13
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-dim原创 2017-05-23 15:50:48 · 314 阅读 · 0 评论 -
leetcode week4
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原创 2017-03-25 13:49:01 · 193 阅读 · 0 评论 -
leetcode week3
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.0 ≤ x, y < 2原创 2017-03-25 13:22:01 · 231 阅读 · 0 评论 -
leetcode week8
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.原创 2017-04-10 16:20:01 · 277 阅读 · 0 评论 -
leetcode week7
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 "原创 2017-04-10 15:22:51 · 204 阅读 · 0 评论 -
leetcode week6
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 return i原创 2017-04-10 14:14:37 · 207 阅读 · 0 评论 -
leetcode week5
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 sam原创 2017-04-10 13:16:50 · 204 阅读 · 0 评论 -
leetcode week1
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you原创 2017-02-26 23:40:45 · 228 阅读 · 0 评论 -
算法概论课后习题8.3
STINGY SAT is the following problem: given a set of clauses (each a disjunction of literals) and an integer k, find a satisfying assignment in which at most k variables are true, if such an assi原创 2017-06-26 13:40:38 · 373 阅读 · 0 评论