
leetcode
bae_
趁着年轻,好好学习
展开
-
Reverse bits leetcode190
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110原创 2015-05-09 23:17:54 · 328 阅读 · 0 评论 -
Longest Palindromic Substring leetcode 5
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.求字符串的最长回文串1,从字符串第一个字符开始遍历,向原创 2015-05-23 13:19:56 · 301 阅读 · 0 评论 -
Longest Substring Without Repeating Characters leetcode3
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “原创 2015-05-24 01:30:48 · 233 阅读 · 0 评论 -
Distinct Subsequences leetcode 115
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of原创 2015-06-09 17:55:26 · 339 阅读 · 0 评论 -
Isomorphic Strings leetcode 205
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another chara原创 2015-07-02 22:25:48 · 318 阅读 · 0 评论 -
Lowest Common Ancestor of a Binary Search Tree leetcode235
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two原创 2015-07-11 15:44:03 · 299 阅读 · 0 评论 -
Clone Graph Leetcode 133
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ’s undirected graph serialization:Nodes are labeled uniquely. We use # as a separator for each node, an原创 2015-06-14 22:50:11 · 321 阅读 · 0 评论 -
Longest Common Prefix leetcode 14
Write a function to find the longest common prefix string amongst an array of strings. 找所有字符串的公共前缀,简单地实现题class Solution {public: string strPrefix(string s1,string s2){ if(s1.length()==0||s原创 2015-06-15 18:14:44 · 305 阅读 · 0 评论 -
Lowest Common Ancestor of a Binary Tree leetcode236
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and原创 2015-07-13 19:40:44 · 387 阅读 · 0 评论 -
Multiply Strings leetcode 43
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.经典的大数相乘问题: 1,从给定字符串最后一位开始操作,要弄清楚整个乘法的过程以及各进位的原创 2015-06-03 23:48:49 · 462 阅读 · 0 评论 -
happy number leetcode202
Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of i原创 2015-05-09 22:50:37 · 383 阅读 · 0 评论 -
Reverse Linked List LeetCode206
reverse a singly linked list 题目比较简单,就是反转一个链表.要求用iteratively (迭代)和recursively(递归)解决/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNo原创 2015-05-07 14:35:48 · 325 阅读 · 0 评论 -
Binary Tree Preorder Traversal leetcode144
Given a binary tree, return the preorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3].Note: Recursive solution is trivial,原创 2015-05-10 21:41:13 · 317 阅读 · 0 评论 -
Binary Tree Postorder Traversal leetcode145
Given a binary tree, return the postorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3},1 \ 2 / 3return [3,2,1]. Note: Recursive solution is trivial, cou原创 2015-05-14 17:27:31 · 443 阅读 · 0 评论 -
Reverse Linked List II Leetcode92
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 the followi原创 2015-05-17 01:50:06 · 295 阅读 · 0 评论 -
Binary Tree Inorder Traversal leetCode11
Given a binary tree, return the inorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,3,2].Note: Recursive solution is trivial,原创 2015-05-27 19:16:31 · 283 阅读 · 0 评论 -
ZigZag Conversion leetcode6
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 N A P L原创 2015-05-18 00:22:19 · 253 阅读 · 0 评论 -
Simplify Path Leetcode71
Given an absolute path for a file (Unix-style), simplify it.For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c”click to show corner cases. Corner Cases:Did you consider the ca原创 2015-05-31 00:52:17 · 470 阅读 · 0 评论 -
Minimum Path Sum leetcode 64
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any原创 2015-05-28 19:21:46 · 366 阅读 · 0 评论 -
Edit Distance Leetcode 72
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) In原创 2015-06-02 23:31:41 · 369 阅读 · 0 评论 -
Palindrome Linked List leetcode 234
Given a singly linked list, determine if it is a palindrome.Follow up: Could you do it in O(n) time and O(1) space?判断给定的链表是不是回文的:把要判断的链表分成两部分,将第二部分逆置,逐个与前一部分的val相比较,若不同返回false/** * Definition for sin原创 2015-07-21 09:31:36 · 468 阅读 · 0 评论