V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  nenseso  ›  全部回复第 7 页 / 共 10 页
回复总数  187
1  2  3  4  5  6  7  8  9  10  
想问下过来人,到底要不要生娃,感觉总是听到带娃产生的矛盾
跟你差不多,虽然我不懦弱,但是性格也很内向,跟周围人很难处人际关系
324 天前
回复了 nenseso 创建的主题 程序员 二叉树中序遍历报错
@ccpp132 的确可以。。。加了个 tmp 保存原 cur ,然后`tmp->left = nullptr; `破坏就能通过了
```
class Solution {
public:

TreeNode *preNode(TreeNode *root) {
if (root == nullptr) return nullptr;
if (root->left == nullptr) return nullptr;
TreeNode *cur = root->left;
while (cur->right != nullptr) {
if (cur->right == root) {
break;
}
cur = cur->right;
}
return cur;
}

vector<int> inorderTraversal(TreeNode* root) {
if (root == nullptr) return {};
TreeNode *cur = root;
std::vector<int>res;

while (cur != nullptr) {
if (cur->left != nullptr) {
TreeNode *pre = preNode(cur);
if (pre->right != nullptr) {
res.push_back(cur->val);
cur = cur->right;
} else {
pre->right = cur;
TreeNode *tmp = cur;
cur = cur->left;
tmp->left = nullptr;
}
} else {
res.push_back(cur->val);
cur = cur->right;
}
}

return res;
}

};
```
324 天前
回复了 nenseso 创建的主题 程序员 二叉树中序遍历报错
@ccpp132 猜测是这样的,不过这样不能解释为啥上面的人转 go 可以跑通。。。我刚测试了一下 swift ,也是可以通的,代码如下,并没有加 pre->right = nil 这样的恢复操作,估计 C++的运行方式应该是有些不同
class Solution {
func preNode(_ root: TreeNode?) -> TreeNode? {
guard let root = root else {return nil}
if root.left == nil {return nil}
var cur = root.left
while cur?.right != nil {
if cur?.right === root {break}
cur = cur?.right
}
return cur
}

func inorderTraversal(_ root: TreeNode?) -> [Int] {
guard let root = root else {return []}
var cur: TreeNode? = root
var res: [Int] = []
while (cur != nil) {
if cur!.left != nil {
let pre = preNode(cur)!;
if pre.right === cur {
res.append(cur!.val)
cur = cur!.right
} else {
pre.right = cur
cur = cur!.left
}
} else {
res.append(cur!.val)
cur = cur!.right
}
}
return res
}
}
324 天前
回复了 nenseso 创建的主题 程序员 二叉树中序遍历报错
@eaststarpen 这种解法是为了达到循环不使用存储结构的目的。为什么要判断 cur->right == root,是因为我改了前驱节点的右指针指向,目的是为了判断 cur 的左子树是否遍历过。
代码中有一句判断是:
if (cur->left != nullptr) {
//.. .省略
} else {
pre->right = cur; // 这一句的目的是让前驱节点的右节点指向 cur ,方便后面遍历到前驱的时候,可以直接跳右节点调回去
cur = cur->left;
}
324 天前
回复了 nenseso 创建的主题 程序员 二叉树中序遍历报错
@mainjzb 比较离谱的是我把答案改成下面就能过了,只是在检测到前驱节点的右节点不为空的时候(说明此时左子树已全部遍历完毕),加了一句`pre-right = nullptr;`把状态置回去,但是我总觉得这句没啥必要,因为我的 cur 节点很快就跳到右子树去了。
```
TreeNode *preNode(TreeNode *root) {
if (root == nullptr) return nullptr;
if (root->left == nullptr) return nullptr;
TreeNode *cur = root->left;
while (cur->right != nullptr) {
if (cur->right == root) {
break;
}
cur = cur->right;
}
return cur;
}

vector<int> inorderTraversal(TreeNode* root) {
if (root == nullptr) return {};
TreeNode *cur = root;
std::vector<int>res;

while (cur != nullptr) {
if (cur->left != nullptr) {
TreeNode *pre = preNode(cur);
if (pre->right != nullptr) {
pre->right = nullptr;
res.push_back(cur->val);
cur = cur->right;
} else {
pre->right = cur;
cur = cur->left;
}
} else {
res.push_back(cur->val);
cur = cur->right;
}
}

return res;
}
```
我一开始的解法自己在本地上跑也是没问题的,但是放到 leetcode 上就报上面的问题。
@you222
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
68aab7367876 copilot-gpt4-service "./myapp" 17 minutes ago Up 17 minutes 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp cool_almeida
运行起来了,我刚刚在接口那里填写 http://127.0.0.1:8080 ,并填写 key 后就能正常访问了,感谢作者
@you222
❯ export GOPROXY=https://goproxy.io,direct
❯ go env -w GOPROXY=https://goproxy.io,direct
❯ go env -w GO111MODULE=on
❯ sudo docker build -t copilot-gpt4-service .
[+] Building 21.5s (13/13) FINISHED docker:rancher-desktop
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 581B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/alpine:latest 2.8s
=> [internal] load metadata for docker.io/library/golang:latest 2.9s
=> [builder 1/4] FROM docker.io/library/golang:latest@sha256:672a2286da3ee7a854c3e0a56e0838918d0dbb1 0.0s
=> [stage-1 1/3] FROM docker.io/library/alpine:latest@sha256:51b67269f354137895d43f3b3d810bfacd39454 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 42.82kB 0.0s
=> CACHED [stage-1 2/3] WORKDIR /app 0.0s
=> CACHED [builder 2/4] WORKDIR /app 0.0s
=> [builder 3/4] COPY . . 0.1s
=> [builder 4/4] RUN CGO_ENABLED=0 GOOS=linux go build -o myapp . 18.5s
=> [stage-1 3/3] COPY --from=builder /app/myapp . 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:9bf73add4942edcf39c4bd992c896073947ef61a87e89384cb31be3b98567666 0.0s
=> => naming to docker.io/library/copilot-gpt4-service 0.0s

不知道为什么 goproxy.cn 不行,我之前还试了阿里云的也不行
❯ sudo docker build -t copilot-gpt4-service .
Password:
Sorry, try again.
Password:
[+] Building 172.1s (13/14) docker:rancher-desktop
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 581B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/golang:latest 3.5s
=> [internal] load metadata for docker.io/library/alpine:latest 3.5s
=> [auth] library/alpine:pull token for registry-1.docker.io 0.0s
=> [auth] library/golang:pull token for registry-1.docker.io 0.0s
=> [builder 1/4] FROM docker.io/library/golang:latest@sha256:672a2286da3ee7a854c3e0a56e0838918d0dbb1c18652992930293312de898a6 0.0s
=> [stage-1 1/3] FROM docker.io/library/alpine:latest@sha256:51b67269f354137895d43f3b3d810bfacd3945438e94dc5ac55fdac340352f48 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 48.47kB 0.0s
=> CACHED [stage-1 2/3] WORKDIR /app 0.0s
=> CACHED [builder 2/4] WORKDIR /app 0.0s
=> [builder 3/4] COPY . . 0.0s
=> ERROR [builder 4/4] RUN CGO_ENABLED=0 GOOS=linux go build -o myapp . 168.5s
------
> [builder 4/4] RUN CGO_ENABLED=0 GOOS=linux go build -o myapp .:
0.232 go: downloading github.com/gin-gonic/gin v1.7.4
168.5 utils/utils.go:13:3: github.com/gin-gonic/[email protected]: Get "https://goproxy.cn/github.com/gin-gonic/gin/@v/v1.7.4.zip": net/http: TLS handshake timeout
------
Dockerfile:13
--------------------
11 |
12 | # 构建应用程序
13 | >>> RUN CGO_ENABLED=0 GOOS=linux go build -o myapp .
14 |
15 | # 第二阶段:运行阶段
--------------------
ERROR: failed to solve: process "/bin/sh -c CGO_ENABLED=0 GOOS=linux go build -o myapp ." did not complete successfully: exit code: 1
有大佬指点一下吗?我一直卡在这里
338 天前
回复了 RanShunliu 创建的主题 职场话题 211 本,选广州公务员还是 C++制造业?
能上岸肯定选上岸啊
当然是国企躺平啦
iOS 开发应该不知道,没这么大的权限,可能是通过其他渠道,后台之类的了解到的吧
355 天前
回复了 brader 创建的主题 程序员 IOS 开发 object-c 中关键字的问题
https://github.com/CoderMJLee/MJExtension?tab=readme-ov-file#-model-name---json-key-mapping%E6%A8%A1%E5%9E%8B%E4%B8%AD%E7%9A%84%E5%B1%9E%E6%80%A7%E5%90%8D%E5%92%8C%E5%AD%97%E5%85%B8%E4%B8%AD%E7%9A%84key%E4%B8%8D%E7%9B%B8%E5%90%8C%E6%88%96%E8%80%85%E9%9C%80%E8%A6%81%E5%A4%9A%E7%BA%A7%E6%98%A0%E5%B0%84
```
@interface Bag : NSObject
@property (copy, nonatomic) NSString *name;
@property (assign, nonatomic) double price;
@end

@interface Student : NSObject
@property (copy, nonatomic) NSString *ID;
@property (copy, nonatomic) NSString *desc;
@property (copy, nonatomic) NSString *nowName;
@property (copy, nonatomic) NSString *oldName;
@property (copy, nonatomic) NSString *nameChangedTime;
@property (strong, nonatomic) Bag *bag;
@end

/***********************************************/

// How to map
[Student mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
return @{
@"ID" : @"id",
@"desc" : @"description",
@"oldName" : @"name.oldName",
@"nowName" : @"name.newName",
@"nameChangedTime" : @"name.info[1].nameChangedTime",
@"bag" : @"other.bag"
};
}];
// Equals: Student.m implements +mj_replacedKeyFromPropertyName method.

NSDictionary *dict = @{
@"id" : @"20",
@"description" : @"kids",
@"name" : @{
@"newName" : @"lufy",
@"oldName" : @"kitty",
@"info" : @[
@"test-data",
@{
@"nameChangedTime" : @"2013-08"
}
]
},
@"other" : @{
@"bag" : @{
@"name" : @"a red bag",
@"price" : @100.7
}
}
};

// JSON -> Student
Student *stu = [Student mj_objectWithKeyValues:dict];

// Printing
NSLog(@"ID=%@, desc=%@, oldName=%@, nowName=%@, nameChangedTime=%@",
stu.ID, stu.desc, stu.oldName, stu.nowName, stu.nameChangedTime);
// ID=20, desc=kids, oldName=kitty, nowName=lufy, nameChangedTime=2013-08
NSLog(@"bagName=%@, bagPrice=%f", stu.bag.name, stu.bag.price);
// bagName=a red bag, bagPrice=100.700000
```
I guess 他在找这个?
359 天前
回复了 Mangle 创建的主题 iDev 2023 ios 该如何学习
UI
- 语言 swift OC
- 常用的组件 UIkit 相关控件
- APP 的生命周期
第三方包管理工具
- cocoapods 的使用
网络
- Alamofire (swift)
- AFNetworking (OC)
本地存储
- 沙盒
- UserDefaults
- FMDB (第三方)
- Realm (第三方,不用写 SQL)
多线程
- GCD
发布流程
- 账号管理
- 签名原理
--------------
没想到 23 年了还是有人学 iOS ,其实现在已经没啥人录制新手视频了,因为老鸟们都找不到工作了,我刚上官网看了一下,其实苹果自己的教程是精心设计过的,肯定还是比我们推荐的要好上手的 https://developer.apple.com/tutorials/SwiftUI
我老婆也是开发,当时怀孕初期因为每天加班到 9 点,自然流产了
2023-11-03 08:50:14 +08:00
回复了 Socrazy 创建的主题 Apple 从 Intel Mac 转到 M2, MS Office 还是跳得欢
@youthfire 不好意思说错了,mac 上哪来的热启动的说法?
2023-11-03 08:49:37 +08:00
回复了 Socrazy 创建的主题 Apple 从 Intel Mac 转到 M2, MS Office 还是跳得欢
@youthfire mac 上哪来的冷启动?
2023-11-01 09:07:18 +08:00
回复了 lzjunika 创建的主题 职场话题 当技术团队没事干了,还能干什么
优化自己的产品体验
2023-10-31 10:07:19 +08:00
回复了 iPhoneilike 创建的主题 MacBook Pro 新 MacBook pro14 大降价!
请问 8g 内存能干嘛? 16g 现在都嫌少了
2023-10-30 19:51:05 +08:00
回复了 wa007 创建的主题 生活方式 如果你实现了财富自由,真的会每天看书旅游吗
今晚做梦的素材有了
1  2  3  4  5  6  7  8  9  10  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2639 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 29ms · UTC 11:06 · PVG 19:06 · LAX 03:06 · JFK 06:06
Developed with CodeLauncher
♥ Do have faith in what you're doing.