- 博客(20)
- 收藏
- 关注
转载 LeetCode---(67) 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
2015-05-22 15:58:19 266
转载 LeetCode---(125) Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is not a
2015-05-21 18:18:16 237
转载 LeetCode---(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
2015-05-20 15:19:46 156
转载 LeetCode---(82) Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1->1-
2015-05-19 22:54:20 172
转载 LeetCode---(83) Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 首先我要在纸上,给出几个用例,找出边界用例和特
2015-05-19 21:23:21 202
原创 LeetCode---(86) 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
2015-05-19 20:07:15 210
转载 LeetCode---(92) Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Given m, n satisfy t
2015-05-19 17:03:03 153
原创 LeetCode---(206)Reverse Linked List
Reverse a singly linked list. 输入一个链表的头结点,反转该链表并输出翻转后链表的头结点。 第一种: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val
2015-05-19 16:59:00 179
原创 LeetCode---(136) Single Number
Given an array of integers, every element appears twice except for one. Find that single one. 常规的做法,就是把数组排序,然后进行比较 class Solution { public: int singleNumber(vector& nums) { in
2015-05-18 15:07:13 168
原创 LeetCode---(70)Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 这道题目是求跑楼梯的可行解法数量。每一步可以
2015-05-18 14:33:02 181
原创 LeetCode---(73) Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 第一种:O(m + n) space O(m*n) time class Solution { public: void setZeroes(vector>& matrix) {
2015-05-18 14:27:56 293
转载 LeetCode---(36) Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. Note: A vali
2015-05-14 17:01:05 162
原创 LeetCode---(31) Next Permutation
题意寻找比当前排列顺序大的下一个排列。 因为降序序列是没法变的更大的,所以从后往前找到第一个升序对的位置。 然后就存在调整大小排列顺序的可能,从后往前找到比当前位置大的元素,交换之。 当前位置后面的元素还是降序排列,将他们反转得到最小顺序排列。其实就是原来当前位置元素后面是最大的排列,而交换后的新元素之后是最小的排列,他们就是相邻的顺序。 当不存在升序,则当前排列是
2015-05-13 22:39:30 211
转载 LeetCode---(27) Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length.
2015-05-13 22:21:02 169
转载 LeetCode---(26) Remove Duplicates from Sorted Array
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 wi
2015-05-13 16:51:21 248
原创 LeetCode---(2) Add Two Number
Problem You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and retu
2015-05-11 16:12:45 190
原创 LeetCode---(18) 4 Sum
Problem: 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.
2015-05-11 14:16:17 253
原创 LeetCode---(16) 3 Sum 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 exact
2015-05-10 21:28:05 271
转载 LeetCode---(15) 3 sum
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: Elements in a triplet (a,b,c)
2015-05-09 22:22:48 306
原创 LeetCode---(1) Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, whe
2015-05-09 17:05:00 191
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人