File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -215,6 +215,38 @@ public:
215
215
216
216
## 其他语言版本
217
217
218
+ ### C:
219
+
220
+ ``` C
221
+ /* *
222
+ * Note: The returned array must be malloced, assume caller calls free().
223
+ */
224
+ int * dailyTemperatures (int* temperatures, int temperaturesSize, int* returnSize) {
225
+ int len = temperaturesSize;
226
+ * returnSize = len;
227
+
228
+ int *result = (int *)malloc(sizeof(int) * len);
229
+ memset(result, 0x00, sizeof(int) * len);
230
+
231
+ int stack[len];
232
+ memset(stack, 0x00, sizeof(stack));
233
+ int top = 0;
234
+
235
+ for (int i = 1; i < len; i++) {
236
+ if (temperatures[i] <= temperatures[stack[top]]) { /* push */
237
+ stack[++top] = i;
238
+ } else {
239
+ while (top >= 0 && temperatures[i] > temperatures[stack[top]]) { /* stack not empty */
240
+ result[stack[top]] = i - stack[top];
241
+ top--; /* pop */
242
+ }
243
+ stack[++top] = i; /* push */
244
+ }
245
+ }
246
+ return result;
247
+ }
248
+ ```
249
+
218
250
### Java:
219
251
220
252
```java
You can’t perform that action at this time.
0 commit comments