算法题目笔记
QxQ_Alter
这个作者很懒,什么都没留下…
展开
-
Roman to Integer
题目描述Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.思路做这道题之前我们首先要懂得罗马数字的写法。 I -> 1 V -> 5 X->10 L-> 50 C->100 D->500 M->10001.相同的数字连写、所表示的数原创 2017-09-24 15:35:25 · 163 阅读 · 0 评论 -
Path Sum II
Path Sum II Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum. For example: Given the below binary tree and sum = 22, return [ [5,4,11,原创 2018-01-21 00:39:53 · 167 阅读 · 0 评论 -
Path sum
Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. Given the below binary tree and sum = 22原创 2018-01-21 00:39:14 · 182 阅读 · 0 评论 -
Swap Nodes in Pairs
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 o原创 2018-01-21 00:36:38 · 195 阅读 · 0 评论 -
算法概论习题
8.3. STINGY SAT is the following problem: given a set of clauses (each a disjunction of literals) and an integer k, and a satisfying assignment in which at most k variables are true, if such an assignm原创 2018-01-21 00:35:54 · 394 阅读 · 0 评论 -
Pow(x, n)
50. Pow(x, n) Implement pow(x, n). example1 Input: 2.00000, 10 Output: 1024.00000 example2 Input: 2.10000, 3 Output: 9.26100 这道题要我实现pow(x,n)这个函数,也就是x的n次方的计算。 class Solution { pu原创 2018-01-20 21:10:42 · 201 阅读 · 0 评论 -
Group Anagrams
Group Anagrams Given an array of strings, group anagrams together. For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], renturn: [ [“ate”, “eat”,”tea”], [“nat”,”tan”],原创 2018-01-20 20:59:37 · 165 阅读 · 0 评论 -
Median of Two Sorted Arrays
Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n))原创 2018-01-20 19:31:09 · 127 阅读 · 0 评论 -
Multiply Strings
Multiply Strings Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2. note: The length of both num1 and num2 is Both num1 and num2 contains o原创 2018-01-20 19:06:15 · 200 阅读 · 0 评论 -
Integer to Roman
Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 之前写过将罗马数转化为整数,现在回顾一下罗马数的写法 I -> 1 V -> 5 X->10 L-> 50原创 2018-01-20 18:38:45 · 125 阅读 · 0 评论 -
Two Sum
Two Sum 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原创 2018-01-20 18:08:43 · 211 阅读 · 0 评论 -
Valid Parentheses
Valid Parentheses Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must close in the correct order, “()” and “()[原创 2018-01-20 17:56:02 · 150 阅读 · 0 评论 -
Longest Common Prefix
Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings. 以第一个String为标准,所有其他的String与第一个String比较,初始化一个String类型prefix来记录结果,当任意一个其他String的第k位与第一个Strin原创 2018-01-20 17:43:33 · 129 阅读 · 0 评论 -
Palindrome Number
Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. 要看x是否是回数,应该初始化一个int类型z,让x的最高位数=z的最低位数,x的第二高位数=z的第二低位数,并以此类推。 代码块 代码块语法遵循标准markdown代码,例如: class S原创 2018-01-20 17:28:51 · 151 阅读 · 0 评论 -
Count and say[easy on LeetCode]
Count and say[easy on LeetCode]原题地址:https://leetcode.com/problems/count-and-say/description/题目描述The count-and-say sequence is the sequence of integers with the first five terms as following: 1 1原创 2017-09-11 19:28:23 · 214 阅读 · 0 评论 -
Merge Two Sorted Lists
题目描述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.思路要把两个已经排序的list(L1, L2)合并并且排好序。那么首先比较的就是两个队列的head,然后将val原创 2017-09-24 16:42:59 · 165 阅读 · 0 评论 -
Triangle
Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,原创 2018-01-21 00:40:21 · 217 阅读 · 0 评论