gatieme / codinginterviews Goto Github PK
View Code? Open in Web Editor NEW剑指Offer——名企面试官精讲典型编程题
License: GNU General Public License v3.0
剑指Offer——名企面试官精讲典型编程题
License: GNU General Public License v3.0
第29题是统计数组中出现次数超过一半的数字,但题目表述却是全排列问题:
void push(int node) { stackIn.push(node); } //不会导致队列顺序出错吗?
倒数第二个代码段,形参base赋值给int类型的temp,可能导致原base精度丢失。
k
步相遇s
长度m
r
2k-k=nr=r
s=k-m=r-m
a
走了不到整条链,比整条链少r-m
长度,然后b
走了整条链加上m
长度b
比a
多走的可以分成两段
a
也走过(所以这一部分b
刚好走过两倍a
走过的长度)a
从链的起点到环的起点r-m
步就可以相遇 class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
next = null;
}
}
public class Solution {
public ListNode detectCycle(ListNode head) {
ListNode p1 = head, p2 = head;
while (p1 != null && p2 != null) {
p1 = p1.next;
if (p2.next == null) {
return null;
}
p2 = p2.next.next;
if (p1 == p2) {
break;
}
}
if (p1 == null || p2 == null) {
return null;
}
p1 = head;
while (p1 != p2) {
p1 = p1.next;
p2 = p2.next;
}
return p1;
}
}
``
#include
using namespace std;
#define __tmain main
class Solution
{
public:
void replaceSpace(char *str,int length)
{
int i, j;
int count = 0;
int len = length;
for(int i = 0; i < length; i++)
{
if(str[i] == ' ')
{
count++;
}
}
len = length + count * 2;
for(i = length - 1, j = len - 1;
i >= 0 && j >= 0;)
{
if(str[i] == ' ')
{
str[j--] = '0';
str[j--] = '2';
str[j--] = '%';
i--;
}
else
{
str[j--] = str[i--];
}
}
str[len] = '0';
}
};
int __tmain( )
{
char str[10 + 1] = "a b c d";
Solution solu;
solu.replaceSpace(str, 10);
cout <<str <<endl;
return 0;
}
``
char str[10 + 1] = "a b c d";
换成:
char str[7 + 1] = "a b c d";
报错:
a%20b%20c%20d
*** stack smashing detected ***: ./004 terminated
已放弃 (核心已转储)
每次喊到_m_的那个小朋友要出列唱首歌,然后可以在礼品箱中任意的挑选礼物,并且不再回到圈中,从他的下一个小朋友开始,继续0...m-1报数....这样下去....直到剩下最后一个小朋友,可以不用表演,
应该是是每次喊到_m-1_的那个小朋友
idea is good
but code not even strcat .....
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.