- 博客(7)
- 收藏
- 关注
原创 Roman to Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 右加左減: 在較大的羅馬數字的右邊記上較小的羅馬數字,表示大數字加小數字。在較大的羅馬數字的左邊記上較小的羅馬數字,表示大數字减小數字。 class Solutio
2015-05-31 20:04:12 228
原创 Add Binary
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". class Solution { public: string addBinary(string a, string b) { int
2015-05-31 15:19:04 322
原创 Reverse Linked List
Reverse a singly linked list. 1、迭代法 遍历该单链表,将节点一个一个摘下来,采用 头插法 插入另一条链表: /** * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */
2015-05-31 10:19:13 159
原创 Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 对于产生一个新的行用从后
2015-05-30 20:40:21 249
原创 Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] class Solution { public:
2015-05-30 19:48:31 252
原创 Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element
2015-05-30 16:30:46 238
原创 Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element
2015-05-30 16:05:52 244
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人